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

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

add design target for documents productions

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