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

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

test (not yet ok) with idldoc 3.2 using rst headers

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.0 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#
48set +u
49while [ ! -z "${1}" ]
50do
51   case ${1} in
52      -i)
53         dirhtml=${2}
54         shift
55      ;;
56      -r)
57         refhtml=${2}
58         shift
59      ;;
60      -e)
61         element=${2}
62         shift
63      ;;
64      -h)
65         echo "${usage}"
66         exit 0
67      ;;
68      *)
69         # other choice
70         echo "${usage}"
71         exit 1
72      ;;
73   esac
74   # next flag
75   shift
76done
77#
78set -u
79#
80# check for dirhtml
81if [ ! -d ${dirhtml} ]
82then
83   echo "eee : ${dirhtml} not found"
84   exit 1
85fi
86# ++ check for readable/writable
87#
88# check for refhtml
89if [ ! -d ${refhtml} ]
90then
91   echo "eee : ${refhtml} not found"
92   exit 1
93fi
94# ++ check for readable
95#
96# check for element
97if [ "${element}" == "" ]
98then
99   echo "eee : ${element} empty"
100   exit 1
101fi
102#
103# first find all files containing <element>...</element>
104list_html_element=$(find ${dirhtml} -name "*.html" -exec grep -l "<${element}>.*</${element}>" {} \;)
105if [ "${list_html_element}" == "" ]
106then
107   echo "iii : no <${element}>...</${element}> in html files"
108else
109   for file_html in ${list_html_element}
110   do
111      #echo "file_html ${file_html}"
112      #read a
113      fpath=$(dirname ${file_html} | sed -e "s+\(${dirhtml}/\)\(.*\)+\2+")
114      #echo "fpath ${fpath}"
115      #read a
116      list_link=$(tr -s " " "\n" < ${file_html} | grep "<${element}>.*</${element}>" | sed -e "s/^.*<${element}>//" -e "s/<\/${element}>.*$//")
117      # echo "liste link" ${list_link}
118      # read a
119      for link in ${list_link}
120      do
121         # replace <element>something</element> by
122         #<a href="something.html">something</a>
123         # modulehtml is the html file name to be used
124         modulehtml=${link}.html
125         # lpath is the path on module relatively to the location of
126         # the html file containing the <element>...</element>
127         lpath=$(find ${refhtml} -name "${modulehtml}")
128         if [ "${lpath}" = "" ]
129         then
130            echo "eee : path of ${modulehtml} not found under ${refhtml}"
131            echo "eee : ${link} is used in ${file_html}"
132         else
133            lpath=$(dirname ${lpath} | sed -e "s+\(${refhtml}/\)\(.*\)+\2+")
134            #echo "path du fichier html ${fpath}"
135            #echo "lpath ${lpath}"
136            #read a
137            if [ "${lpath}" = "${fpath}" ]
138            then
139               path="./"
140            fi
141            if [ "${lpath:0:1}" = "/" ]
142            then
143               # absolute path
144               path=${lpath}
145            else
146               nblev=$(echo ${fpath} |  sed -e "s@/\$@@" | awk -F "/" '{print NF}')
147               relpath=""
148               ilev=1
149               while [ ${ilev} -le ${nblev} ]
150               do
151                  relpath="${relpath}../"
152                  ilev=$(( ${ilev} + 1 ))
153               done
154               path=${relpath}/${lpath}
155            fi
156            #echo "path ${path}"
157            #read a
158            cat <<EOF > /tmp/pro2href${$}.sed
1591{x;s@^@first@;x;}
1601,/<${element}>${link}<\/${element}>/{x;/first/s///;x;s@<${element}>${link}<\/${element}>@<a href="${path}/${link}.html">${link}<\/a>@;}
161EOF
162            sed -f /tmp/pro2href${$}.sed \
163               ${file_html} > ${file_html}_modify
164            #diff  ${file_html}  ${file_html}_modify
165            #read a
166            mv ${file_html}_modify ${file_html}
167            rm /tmp/pro2href${$}.sed
168         fi
169      done
170   done
171fi
172exit 0
Note: See TracBrowser for help on using the repository browser.