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

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 5.3 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
32# occurrences of <pro>...</pro> may not be the same
33# ex: see restoreboxparam.pro : domdef and saveboxparam
34# fplod 2007-06-26T13:32:06Z aedon.locean-ipsl.upmc.fr (Darwin)
35# improvement for multiple occurrences of <pro>...</pro> on one line
36# see http://www.gentoo.org/doc/en/articles/l-sed2.xml
37# sed by example, Part 2
38# especially for directory-overview files
39# fplod 2007-03-20T14:02:14Z aedon.locean-ipsl.upmc.fr (Darwin)
40# creation
41#
42set -o posix
43set -u
44#
45command=$(basename ${0} .sh)
46log_date=$(date -u +"%Y%m%dT%H%M%SZ")
47log=/tmp/${command}.${log_date}
48#
49usage=" Usage : ${command} -i dirhtml -r refhtml -e element"
50#
51while [ ${#} -gt 0 ]
52do
53    case ${1} in
54        -i)
55            dirhtml=${2}
56            shift
57        ;;
58        -r)
59            refhtml=${2}
60            shift
61        ;;
62        -e)
63            element=${2}
64            shift
65        ;;
66        -h)
67            echo "${usage}"
68            exit 0
69        ;;
70        *)
71            # other choice
72            echo "${usage}"
73            exit 1
74        ;;
75    esac
76    # next flag
77    shift
78done
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.