source: trunk/SRC/Documentation/xmldoc/doidldoc.sh @ 415

Last change on this file since 415 was 415, checked in by pinsard, 15 years ago

documentations tools improvements

  • Property svn:executable set to *
  • Property svn:keyword set to Id
  • Property svn:keywords set to Id
File size: 15.3 KB
Line 
1#! /bin/sh
2#+
3#
4# NAME
5# ====
6#
7# idldoc.sh - build idldoc documentations
8#
9# SYNOPSYS
10# ========
11#
12# ``doidldoc.sh -i indir -t title -o outdir -idl_dir idl_dir -idldoc_version idldoc_version -idldoc_dir idldoc_dir``
13#
14# DESCRIPTION
15# ===========
16#
17# Produce HTML files from IDL sources using idldoc.
18#
19# -i directory input
20# -t title
21# -o directory output
22# -idl_dir idl_dir
23# -idldoc_version idldoc_version
24# -idldoc_dir idldoc_dir
25#
26# Two pass : first *classic* idldoc then some home made transformation to avoid
27# for example version of idldoc on each HTML files.
28#
29# The first pass produce files in /tmp/idldoc_output_${$}/ directory.
30#
31# At the end the result is in ``outdir``.
32#
33#
34# By default, embedded ``idldoc`` 2.0 in SAXO is used.
35#
36# You can specified an other ``idldoc`` implentation by specify directory and
37# version using *idldoc_dir* and *idldoc_version*.
38#
39# Be warned that assitant help is only available with ``idldoc 2.0``.
40#
41# CAUTIONS
42# ========
43#
44# SAXO_DIR must be set. The value should be the directory where
45# SAXO is available.
46#
47# for example, if you work at LOCEAN and work with default SAXO,
48# SAXO_DIR=/usr/home/smasson/SAXO_DIR/.
49#
50# For working in progress, you should checkout SAXO on a personnal
51# directory and set SAXO_DIR to the working space.
52#
53# example for me : SAXO_DIR=${HOME}/SAXO_DIR_ws/
54#
55# EXAMPLES
56# ========
57#
58# Results can be seen be opening a browser on /tmp/idldoc_html_output/index.html
59#
60# To produce SAXO HTML outputs :
61# ::
62#
63# $ cd SAXO_DIR_ws/SRC/Documentation/xmldoc/
64# $ ${SAXO_DIR}/SRC/Documentation/xmldoc/doidldoc.sh -i ../.. -t "SAXO Documentation" -o ./idldoc_html_output/ -idl_dir /usr/local_linux/idl/idl_6.4/idl/
65#
66# To produce GEOMAG HTML outputs :
67# ::
68#
69# $ cd /usr/home/fplod/incas/geomag/geomag_ws/
70# $ ${SAXO_DIR}/SRC/Documentation/xmldoc/doidldoc.sh -i . -t "GEOMAG Documentation" -o /usr/work/incas/${LOGNAME}/geomag/idldoc_html_output/ -idl_dir /usr/local_linux/idl/idl_6.4/idl/
71#
72# To produce VARAMMA HTML outputs :
73# ::
74#
75# $ cd /usr/home/fplod/incas/varamma/varamma_ws/
76# $ ${SAXO_DIR}/SRC/Documentation/xmldoc/doidldoc.sh -i . -t "VARAMMA Documentation" -o /tmp/idldoc_html_output/ -idl_dir /usr/local_linux/idl/idl_6.4/idl/
77#
78# To produce POST_IT HTML outputs :
79# ::
80#
81# $ cd /usr/home/fplod/incas/post_it/post_it_ws/
82# $ ${SAXO_DIR}/SRC/Documentation/xmldoc/doidldoc.sh -i . -t "POST_IT/Documentation" -o /usr/work/incas/${LOGNAME}/idldoc_html_output/ -idl_dir /usr/local_linux/idl/idl_6.4/idl/
83#
84
85# TODO
86# ====
87#
88# ++ choix de la version de idldoc et consequences sur assistant
89#
90# ++ choix de la version de IDL et consequences sur assistant et lien sur
91# doc idl
92#
93# SEE ALSO
94# ========
95#
96# idldoc++ lien
97#
98# EVOLUTIONS
99# ==========
100#
101# $Id$
102#
103# - fplod 20091112T101526Z zeus.locean-ipsl.upmc.fr (Linux)
104#
105#   * replace mv by cp -r because mv may no works accross filesystems
106#   * add chek on outdir
107#
108# - fplod 20091112T084225Z aedon.locean-ipsl.upmc.fr (Darwin)
109#
110#   * bug fix if indir is set to '.'
111#   * idl_dir in parameter
112#   * path of local commands
113#
114# - fplod 20091110T151839Z aedon.locean-ipsl.upmc.fr (Darwin)
115#   
116#   * add CAUTIONS about SAXO_DIR environment variable
117#     and usage in EXAMPLES
118#
119# - ++
120#
121# * add idldoc_version and idldoc_dir parameters
122# idldoc version is usefull because parameters of ``idldoc``
123# have been modified (see ``CHARSET`` in 3.1.1.).
124#
125# ``idldoc`` release can not be guessed
126#
127# - fplod 2008-08-11T12:57:48Z aedon.locean-ipsl.upmc.fr (Darwin)
128#
129# * comments in this file in ReST format
130# * add ``-i``, ``-t`` and ``-o`` parameters
131#
132# - fplod 2008-06-20T13:07:59Z aedon.locean-ipsl.upmc.fr (Darwin)
133#
134# * evaluation version 3.1.1
135#
136# we are not yet still ready to migrate to rst format because of lack of
137# assistant transformation independant of IDLdoc release (at least
138# between 2. and 3.)
139#
140# - fplod 2008-01-10T08:13:41Z aedon.locean-ipsl.upmc.fr (Darwin)
141#
142# * version http://cookbook.idldev.com/idldoc-3.0rc2.zip
143#
144# - fplod 2008-01-03T09:59:18Z aedon.locean-ipsl.upmc.fr (Darwin)
145#
146# * version http://cookbook.idldev.com/idldoc-3.0rc1.zip
147#
148# - fplod 2007-12-12T09:47:04Z aedon.locean-ipsl.upmc.fr (Darwin)
149#
150# * version http://michaelgalloy.com/wp-content/uploads/2007/12/idldoc-3.0b4.zip
151#
152# - fplod 2007-12-11T09:14:04Z aedon.locean-ipsl.upmc.fr (Darwin)
153#
154# * version http://michaelgalloy.com/wp-content/uploads/2007/12/idldoc-3.0b4-src.zip
155# * ++ pb path
156# * beginning of docbook templates writing (from html 3.0b3 tt files)
157#
158# - fplod 2007-12-10T09:28:11Z aedon.locean-ipsl.upmc.fr (Darwin)
159#
160# * test with gdl : pas possible car compatibility < 6.1
161#
162# - fplod 2007-12-04T09:21:18Z aedon.locean-ipsl.upmc.fr (Darwin)
163#
164# * version http://michaelgalloy.com/wp-content/uploads/2007/12/idldoc-3.0b3.zip
165# * pb parser if ; after ;-
166# * ++ plus de param et keyword dans l'index
167# * ++ pas w3c tilte au lieu de title, pas de charset, pas de alt, pas de summary
168# * ++ css pas ok
169# * ++ plus de @restrictions
170#
171# - fplod 2007-12-04T09:10:55Z aedon.locean-ipsl.upmc.fr (Darwin)
172#
173# * externalisation of idldoc issues from savesaxo.sh
174# * previous release of idldoc was 2.0
175# * this tool can be checked by creating doc from Michael Galloy librayry
176# available on http://www.michaelgalloy.com/lib-docs/
177# * version http://michaelgalloy.com/wp-content/uploads/2007/11/idldoc-3.0b1.zip
178# * pas ok ne reconnait pas les @param, @keyword
179#-
180#
181system=$(uname)
182case "${system}" in
183AIX|IRIX64)
184 echo " www : no specific posix checking"
185;;
186*)
187 set -o posix
188;;
189esac
190#
191command=$(basename ${0})
192log_date=$(date -u +"%Y%m%dT%H%M%SZ")
193#
194usage=" Usage : ${command} -i indir -t title -o outdir [-idldoc_dir idldoc_dir -idldoc_version idldoc_version]"
195#
196# default ++ pas encore en parametre
197assistant=0
198#assistant=1
199transform=1
200command_dir=$(dirname ${0})
201idldoc_dir="${command_dir}/../idldoc/"
202idldoc_version="2.0"
203unset command_dir
204# default IDL command and directory
205#idl_dir=/usr/local_linux/idl/idl64/  # overriding idl_dir for test ++
206#idldoc_dir="/usr/home/fplod/src/idldoc-3.1.1/" # overriding idldoc_dir for test ++
207#
208minargcount=6
209if [ ${#} -lt ${minargcount} ]
210then
211 echo "eee : not enought arguments"
212 echo "${usage}"
213 exit 1
214fi
215#
216while [ ! -z "${1}" ] # ++ pb bash
217do
218 case ${1} in
219 -i)
220 indir=${2}
221 shift
222 case ${indir} in
223 .)
224  indir=$(pwd)
225  ;;
226 esac
227 ;;
228 -t)
229 title=${2}
230 shift
231 ;;
232 -o)
233 outdir=${2}
234 shift
235 ;;
236 -idldoc_dir)
237 idldoc_dir=${2}
238 shift
239 ;;
240 -idldoc_version)
241 idldoc_version=${2}
242 shift
243 ;;
244 -idl_dir)
245 idl_dir=${2}
246 shift
247 ;;
248 -h)
249 echo "${usage}"
250 exit 0
251 ;;
252 *) # other choice
253 echo "${usage}"
254 exit 1
255 ;;
256 esac
257 shift # next flag
258done
259#
260set -u
261#
262# check for outir
263if [ ! -d ${outdir} ]
264then
265 echo "eee : outdir (${outdir}) not found"
266 exit 1
267fi
268# check for permission access on outdir
269if [ ! -x ${outdir} ]
270then
271 echo " eee : ${outdir} not reachable"
272 exit 1
273 fi
274#
275# check for write permission on outdir
276if [ ! -w ${outdir} ]
277then
278 echo " eee : ${outdir} not writable"
279 exit 1
280fi
281#
282# ++ test si IDL (car GDL inutilisable)
283application=${idl_dir}/bin/idl
284#
285# build a IDL file to launch idldoc
286outputtmp=/tmp/idldoc_output${$}/
287idldoc_log="/tmp/idldochtml_${$}.log"
288pro="/tmp/idldochtml_${$}.pro"
289#
290cd ${idldoc_dir}
291case ${idldoc_version} in
292 3.1.1)
293 cat << EOF > ${pro}
294!path = expand_path('+' + '${idldoc_dir}')
295idldoc,root="${indir}",title="${title}", $
296CHARSET="ISO-8859-15", $
297LOG_FILE="${idldoc_log}", $
298output="${outputtmp}", $
299overview="../../overview", /statistics
300exit
301EOF
302 ;;
303 2.0)
304 cat << EOF > ${pro}
305!path = expand_path('+' + '${idldoc_dir}')
306idldoc,root="${indir}",title="${title}", $
307LOG_FILE="${idldoc_log}", $
308output="${outputtmp}", $
309overview="../../overview", /statistics, /preformat
310exit
311EOF
312 ;;
313 *)
314  echo "eee : idldoc version not implemented ${idldoc_version}"
315  exit 1
316 ;;
317esac
318#
319# launch IDL with the file built above
320export IDL_STARTUP=${pro}
321${application}
322rm ${pro}
323#
324if [ ${transform} -eq 1 ]
325then
326# In order to do not have to many revision in svn, we modify some
327# lines produced by idldoc :
328# - add Source link in each html file corresponding to a .pro file
329# example :
330# <td>Source</td>
331# will be replaced by
332# <td><a href="../../Calendar/caldat.pro" title="Source code of a file">Source</a></td>
333#
334# - remove version, date and time of idldoc production
335# ++ je ne sais pas dire en sed la ligne suivant l'occurence de Modification date
336#
337# count of directory levels in output
338# this count will be use to format relative path later
339nblev1=$(echo ${outputtmp} | sed -e "s@/\$@@" |awk -F "/" '{print NF}')
340#
341list_html_pro=$(find ${outputtmp} -name "*.html" -exec grep -l "<title>.*\.pro" {} \;)
342for file_html in ${list_html_pro}
343do
344 # build the .pro file name
345 bfile=$(basename ${file_html} .html)
346 # retrieve the path of html file relative to output.
347 # This path will be used in "Source" link.
348 nblev2=$(dirname ${file_html} | sed -e "s@/\$@@" | awk -F "/" '{print NF}')
349 difflev=$((${nblev2} - ${nblev1}))
350 if [ ${difflev} -ge 2 ]
351 then
352 ilev=1
353 reloutput_html=".."
354 while [ ${ilev} -le ${difflev} ]
355 do
356 reloutput_html="${reloutput_html}/.."
357 ilev=$(( ${ilev} + 1 ))
358 done
359 relpath_html=$(dirname ${file_html} | \
360 sed \
361 -e "s@${outputtmp}@${reloutput_html}@" \
362 -e "s@\$@/@")
363 # echo "relpath ${relpath_html})"
364 else
365 relpath_html="./"
366 fi
367 # echo "relpath ${relpath_html}/${bfile}"
368 sed \
369 -e "s@<td >Source<\/td>@<td><a href=\"${relpath_html}/${bfile}.pro\" title=\"Source code of a file\">Source<\/a><\/td>@" \
370 ${file_html} > ${file_html}_modify
371 mv ${file_html}_modify ${file_html}
372done
373list_html=$(find ${outputtmp} -name "*.html")
374for file_html in ${list_html}
375do
376 sed \
377 -e "s/\(Generated by IDLdoc\)\( .* on .*\)\( -->\)/\1\3/" \
378 -e "s/\(Produced by IDLdoc\)\( .* on .*\)\(<\/td>\)/\1\3/" \
379 -e "/<h2>Produced on/d" \
380 -e "/Modifcation:/d" \
381 -e "/<td>... ... .* ..:..:.. ....<\/td>/d" \
382 -e 's@<div class="value">@<div class="preformat">@' \
383 -e 's/div\#file_comments {/div\#file_comments { white-space: pre;/' \
384 -e 's@^ <fixe>@<pre>@' \
385 -e 's@^ </fixe>@</pre>@' \
386 -e 's@xhtml-transitional@xhtml1-transitional@' \
387 ${file_html} > ${file_html}_modify
388 mv ${file_html}_modify ${file_html}
389done
390# suppress ".html" in idldoc-index*.html in lines like
391# a parameter from the routine ./ReadWrite/idl-NetCDF/ncdf_read.html
392list_html=$(find ${outputtmp} -name "idldoc-index*.html")
393for file_html in ${list_html}
394do
395 sed \
396 -e "s/\(a parameter from the routine \)\(.*\)\(.html\)/\1\2/" \
397 ${file_html} > ${file_html}_modify
398 mv ${file_html}_modify ${file_html}
399done
400# replace <pro>ginette</pro> by a sequence like
401# <a href="./ginette.html">ginette</a>
402${SAXO_DIR}/SRC/Documentation/xmldoc/pro2href.sh -i ${outputtmp} -r ${outputtmp} -e pro
403status=${?}
404if [ ${status} -ne 0 ]
405then
406 echo "eee : pb during pro2href.sh for <pro>...</pro>"
407 exit 1
408fi
409# replace <proidl>ginette</proidl> by a sequence like
410# <a href="./ginette.html">ginette</a>
411${SAXO_DIR}/SRC/Documentation/xmldoc/pro2href.sh -i ${outputtmp} -r ${idl_dir}/help/online_help -e proidl
412status=${?}
413if [ ${status} -ne 0 ]
414then
415 echo "eee : pb during pro2href.sh for <proidl>...</proidl>"
416 exit 1
417fi
418fi # end of transform = 1
419#
420#
421if [ ${assistant} -eq 1 ]
422then
423 # build a IDL file to launch idldoc
424 idldoc_log="/tmp/idldocassistant_${$}.log"
425 pro="/tmp/idldocassistant_${$}.pro"
426 case ${idldoc_version} in
427 3.1.1)
428  echo "iii : assistant is not feasable with idldoc > 2.0"
429 ;;
430 2.0)
431  cat << EOF > ${pro}
432!path = expand_path('+' + '${idldoc_dir}')
433idldoc,root="${indir}",title="${title}", $
434LOG_FILE="${idldoc_log}", $
435output="${outputtmp}", overview='../../overview', /statistics, /embed, /assistant
436exit
437EOF
438 ;;
439 *)
440  echo "eee : idldoc version not implemented ${idldoc_version}"
441  exit 1
442 ;;
443esac
444# launch IDL with the file built above
445IDL_STARTUP=${pro};${idl_dir}/bin/idl
446/bin/rm ${pro}
447# In order to do not have to many revision in svn, we modify some
448# lines produced by idldoc :
449# examples :
450# <!-- Generated by IDLdoc 2.0 on Wed Jun 7 10:25:28 2006 -->
451# will be replaced by
452# <!-- Generated by IDLdoc 2.0 -->
453# <p><font color="gray" size="-3">&nbsp;&nbsp;Produced by IDLdoc 2.0 on Wed Sep 13 16:32:10 2006.</font></p>
454# will be replaced by
455# <p><font color="gray" size="-3">&nbsp;&nbsp;Produced by IDLdoc 2.0</font></p>
456# <h2>Produced on Wed Jun 7 10:23:13 2006</h2>
457# will be delete
458# other lines will be deleted because the time is the time of checkout not
459# the time of revision.
460# the sequence of lines
461#<dl>
462# <dt>Last modification:</dt>
463# <dd>Fri Jun 2 11:46:24 2006</dd>
464# </dl>
465# should also be removed ++ je ne sais pas dire en sed la ligne
466# suivant l'occurence de Last modification
467# replace *_param_* in href attributes because anchors are badly written
468# with _keyword_
469#++ -e 's@\(href="#_.*\)\(_param_\)\(.*"\)@\1_keyword_\3@g' \ # ++ pb global
470# ONLINE_HELP, book="../idldoc_assistant_output/idldoc-lib.adp", /full_path # won't work
471# encaspulate example content in <pre> </pre> in idldoc assistant outputs
472# Examples section is supposed to start with <h3>Examples</h3>
473# and end is before <h3>Version history</h3>
474list_html=$(find ${outputtmp} -name "*.html")
475for file_html in ${list_html}
476do
477 sed \
478 -e "s/\(Generated by IDLdoc 2.0\)\( on .*\)\( -->\)/\1\3/" \
479 -e "s/\(Produced by IDLdoc 2.0\)\( on .*\)\(\.<\/font>\)/\1\3/" \
480 -e "/<h2>Produced on/d" \
481 -e "/Last modification:/d" \
482 -e "/<dd>... ... .* ..:..:.. ....<\/dd>/d" \
483 -e '/href/s@_param_@_keyword_@g' \
484 -e 's@<div class="value">@<div class="preformat">@' \
485 -e 's/div\#file_comments {/div\#file_comments { white-space: pre;/' \
486 -e 's@^ <fixe>@<pre>@' \
487 -e 's@^ </fixe>@</pre>@' \
488 -e "s@<h3>Examples</h3>@<h3>Examples</h3><pre>@" \
489 -e "s@<h3>Version history</h3>@</pre><h3>Version history</h3>@" \
490 ${file_html} > ${file_html}_modify
491 mv ${file_html}_modify ${file_html}
492done
493#
494# replace <pro>ginette</pro> by a sequence like
495# <a href="./ginette.html">ginette</a>
496${SAXO_DIR}/SRC/Documentation/xmldoc/pro2href.sh -i ${outputtmp} -r ${outputtmp} -e pro
497status=${?}
498if [ ${status} -ne 0 ]
499then
500 echo "eee : pb during pro2href.sh for <pro>...</pro>"
501 exit 1
502fi
503# replace <proidl>ginette</proidl> by a sequence like
504# <a href="./ginette.html">ginette</a>
505${SAXO_DIR}/SRC/Documentation/xmldoc/pro2href.sh -i ${outputtmp} -r ${idl_dir}/help/online_help -e proidl
506status=${?}
507if [ ${status} -ne 0 ]
508then
509 echo "eee : pb during pro2href.sh for <proidl>...</proidl>"
510 exit 1
511fi
512# add the directory-overview.html from dir-files.html in idldoc_html_output
513list_html=$(find ../idldoc_html_output -name dir-files.html)
514for file_html in ${list_html}
515do
516 fout=../idldoc_assistant_output/${file_html#../idldoc_html_output/*}
517 fout=${fout%/*}/directory-overview.html
518 cp ${file_html} ${fout}
519done
520# copy listings.css (needed by directory-overview.html files)
521cp ../idldoc/resource/listings.css ${outputtmp}
522# add an id in idldoc-lib.adp
523cat << EOF > /tmp/adp_modification
524<!-- \$Id\$ -->
525EOF
526sed -e "/<\/profile>/r /tmp/adp_modification" \
527 ../idldoc_assistant_output/idldoc-lib.adp > \
528 ../idldoc_assistant_output/idldoc-lib.adp_${$}
529mv ../idldoc_assistant_output/idldoc-lib.adp_${$} \
530../idldoc_assistant_output/idldoc-lib.adp
531rm /tmp/adp_modification
532# check that the number of existing html files for each .pro file is 2!
533for i in $( find ../.. -name "*.pro" )
534do
535 nhtml=$( find ../.. -name $( basename ${i} .pro ).html | wc -l )
536 if [ ${nhtml} -ne 2 ]
537         then
538         echo "ERROR there is no 2 $( basename ${i} .pro ).html files"
539         find ../.. -name $( basename ${i} .pro ).html
540         echo
541 fi
542done
543#
544fi
545# copy of temporary outputs on final directory
546cp -r ${outputtmp}/* ${outdir}
547echo "iii : look at ${outdir}/index.html"
548echo "iii : you can see idldoc log file in ${idldoc_log}"
549echo "iii : and look ${outdir}/idldoc-warnings.html#undoc"
550#
551# end
552exit 0
Note: See TracBrowser for help on using the repository browser.