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

Last change on this file since 376 was 262, checked in by pinsard, 17 years ago

corrections of some headers and parameters and keywords case. change of pro2href to replace proidl

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