source: trunk/SRC/Documentation/xmldoc/pro2href.sh @ 420

Last change on this file since 420 was 420, checked in by pinsard, 14 years ago

documentations tools improvements

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1#! /bin/sh
2#
3# DESCRIPTION
4# ===========
5#
6# replace <element>ginette</element> by a sequence like with element given
7# in argument <a href="./ginette.html">ginette</a>
8# in all html files in dirhtml given in argument
9# We have to deal with the path of ginette.html in refhtml also given in
10# argument.
11#
12# see call in savesaxo.sh
13#
14# EVOLUTIONS
15# ==========
16# $Id$
17#
18# fplod 2007-08-21T09:06:58Z aedon.locean-ipsl.upmc.fr (Darwin)
19# add -e (element) parameter to define element syntax like
20# <pro></pro> or <proidl>...</proidl>
21# add -i parameter : this directory is the one where we are looking for
22# html files to be modified. so replace output by dirhtml
23# add -r parameter :  this directory is the one where we are looking for
24# html files to be linked
25# remove lowercase translation (because of idl help files which are in
26# uppercase)
27# fplod 2007-08-20T11:25:39Z aedon.locean-ipsl.upmc.fr (Darwin)
28# correction from
29# 4.11. How do I match only the first occurrence of a pattern?
30# in sed faq http://www.student.northpark.edu/pemente/sed/sedfaq4.html#s4.11
31#++ still not working perfectly because path of links on the different occurences of <pro>...</pro> may not be the same
32# ex: see restoreboxparam.pro : domdef and saveboxparam
33# fplod 2007-06-26T13:32:06Z aedon.locean-ipsl.upmc.fr (Darwin)
34# improvment for multiple occurences of <pro>...</pro> on one line
35# see http://www.gentoo.org/doc/en/articles/l-sed2.xml
36# Sed by example, Part 2
37# especially for directory-overview files
38# fplod 2007-03-20T14:02:14Z aedon.locean-ipsl.upmc.fr (Darwin)
39# creation
40#
41set -o posix
42command=$(basename ${0} .sh)
43log_date=$(date -u +"%Y%m%dT%H%M%SZ")
44log=/tmp/${command}.${log_date}
45#
46usage=" Usage : ${command} -i dirhtml -r refhtml -e element"
47#
48while [ ! -z "${1}" ]
49do
50 case ${1} in
51 -i) # dirhtml
52  dirhtml=${2}
53  shift
54 ;;
55 -r) # refhtml
56  refhtml=${2}
57  shift
58 ;;
59 -e) # element
60  element=${2}
61  shift
62 ;;
63 -h)
64  echo "${usage}"
65  exit 0
66 ;;
67 *) # other choice
68  echo "${usage}"
69  exit 1
70 ;;
71 esac
72 shift # next flag
73done
74#
75set -u
76#
77# check for dirhtml
78if [ ! -d ${dirhtml} ]
79then
80   echo "eee : ${dirhtml} not found"
81   exit 1
82fi
83# ++ check for readable/writable
84#
85# check for refhtml
86if [ ! -d ${refhtml} ]
87then
88   echo "eee : ${refhtml} not found"
89   exit 1
90fi
91# ++ check for readable
92#
93# check for element
94if [ "${element}" == "" ]
95then
96   echo "eee : ${element} empty"
97   exit 1
98fi
99#
100# first find all files containing <element>...</element>
101list_html_element=$(find ${dirhtml} -name "*.html" -exec grep -l "<${element}>.*</${element}>" {} \;)
102if [ "${list_html_element}" == "" ]
103then
104   echo "iii : no <${element}>...</${element}> in html files"
105else
106   for file_html in ${list_html_element}
107   do
108      #echo "file_html ${file_html}"
109      #read a
110       fpath=$(dirname ${file_html} | sed -e "s+\(${dirhtml}/\)\(.*\)+\2+")
111#echo "fpath ${fpath}"
112#read a
113       list_link=$(tr -s " " "\n" < ${file_html} | grep "<${element}>.*</${element}>" | sed -e "s/^.*<${element}>//" -e "s/<\/${element}>.*$//")
114#      echo "liste link" ${list_link}
115#      read a
116       for link in ${list_link}
117       do
118          # replace <element>something</element> by
119          #<a href="something.html">something</a>
120          # modulehtml is the html file name to be used
121          modulehtml=${link}.html
122          # lpath is the path on module relatively to the location of
123          # the html file containing the <element>...</element>
124          lpath=$(find ${refhtml} -name "${modulehtml}")
125          if [ "${lpath}" = "" ]
126          then
127             echo "eee : path of ${modulehtml} not found under ${refhtml}"
128             echo "eee : ${link} is used in ${file_html}"
129          else
130             lpath=$(dirname ${lpath} | sed -e "s+\(${refhtml}/\)\(.*\)+\2+")
131#echo "path du fichier html ${fpath}"
132#echo "lpath ${lpath}"
133#read a
134             if [ "${lpath}" = "${fpath}" ]
135             then
136                path="./"
137             fi
138             if [ "${lpath:0:1}" = "/" ] # absolute path
139             then
140                path=${lpath}
141             else
142                nblev=$(echo ${fpath} |  sed -e "s@/\$@@" | awk -F "/" '{print NF}')
143                relpath=""
144                ilev=1
145                while [ ${ilev} -le ${nblev} ]
146                do
147                   relpath="${relpath}../"
148                   ilev=$(( ${ilev} + 1 ))
149                done
150                path=${relpath}/${lpath}
151             fi
152#echo "path ${path}"
153#read a
154             cat <<EOF > /tmp/pro2href${$}.sed
1551{x;s@^@first@;x;}
1561,/<${element}>${link}<\/${element}>/{x;/first/s///;x;s@<${element}>${link}<\/${element}>@<a href="${path}/${link}.html">${link}<\/a>@;}
157EOF
158             sed -f /tmp/pro2href${$}.sed \
159             ${file_html} > ${file_html}_modify
160#diff  ${file_html}  ${file_html}_modify
161#read a
162             mv ${file_html}_modify ${file_html}
163             rm /tmp/pro2href${$}.sed
164          fi
165       done
166   done
167fi
168exit 0
Note: See TracBrowser for help on using the repository browser.