1 | #! /bin/sh |
---|
2 | # replace <pro>ginette</pro> by a sequence like |
---|
3 | # <a href="./ginette.html">ginette</a> |
---|
4 | # we have to deal with the path of ginette.html ... |
---|
5 | # |
---|
6 | # see call in savesaxo.sh |
---|
7 | # |
---|
8 | # update : |
---|
9 | # $Id$ |
---|
10 | #++ still not working perfectly because path of links on the different occurences of <pro>...</pro> may not be the same |
---|
11 | # ex: see restoreboxparam.pro : domdef and saveboxparam |
---|
12 | # fplod 2007-06-26T13:32:06Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
13 | # improvment for multiple occurences of <pro>...</pro> on one line |
---|
14 | # see http://www.gentoo.org/doc/en/articles/l-sed2.xml |
---|
15 | # Sed by example, Part 2 |
---|
16 | # especially for directory-overview files |
---|
17 | # fplod 2007-03-20T14:02:14Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
18 | # creation |
---|
19 | # |
---|
20 | set -u |
---|
21 | output=${1} # ++ parameter |
---|
22 | # |
---|
23 | # first find all files containing <pro>...</pro> |
---|
24 | list_html_pro=$(find ${output} -name "*.html" -exec grep -l "<pro>.*</pro>" {} \;) |
---|
25 | if [ "${list_html_pro}" = " " ] |
---|
26 | then |
---|
27 | echo "iii : no <pro>...</pro> in html files" |
---|
28 | else |
---|
29 | for file_html in ${list_html_pro} |
---|
30 | do |
---|
31 | fpath=$(dirname ${file_html} | sed -e "s+\(${output}/\)\(.*\)+\2+") |
---|
32 | list_llink=$(grep -n "<pro>.*</pro>" ${file_html} | awk -F ":" '{print $1}') |
---|
33 | for line in ${list_llink} |
---|
34 | do |
---|
35 | # replace <pro>something</pro> by |
---|
36 | #<a href="something.html">something</a> |
---|
37 | # module is the html file name to be used |
---|
38 | module=$(sed -ne "${line},${line}p" ${file_html} | \ |
---|
39 | grep "<pro>.*</pro>" | \ |
---|
40 | sed -e "s+\(.*<pro>\)\([^<]*\)\(</pro>.*\)+\\2.html+g") |
---|
41 | modulemin=$(echo ${module} | tr "[:upper:]" "[:lower:]" ) |
---|
42 | # lpath is the path on module relatively to the location of |
---|
43 | # the html file containing the <pro>...</pro> |
---|
44 | lpath=$(find ${output} -name "${modulemin}") |
---|
45 | if [ "${lpath}" = "" ] |
---|
46 | then |
---|
47 | echo "eee : path of ${modulemin} not found under ${output}" |
---|
48 | echo "eee : ${module} is used in ${file_html}" |
---|
49 | else |
---|
50 | lpath=$(dirname ${lpath} | sed -e "s+\(${output}/\)\(.*\)+\2+") |
---|
51 | #echo "path du fichier html ${fpath}" |
---|
52 | #echo "lpath ${lpath}" |
---|
53 | if [ "${lpath}" = "${fpath}" ] |
---|
54 | then |
---|
55 | relpath="./" |
---|
56 | else |
---|
57 | nblev=$(echo ${fpath} | sed -e "s@/\$@@" | awk -F "/" '{print NF}') |
---|
58 | # nblev=$(( ${nblev} + 1)) |
---|
59 | relpath="" |
---|
60 | ilev=1 |
---|
61 | while [ ${ilev} -le ${nblev} ] |
---|
62 | do |
---|
63 | relpath="${relpath}../" |
---|
64 | ilev=$(( ${ilev} + 1 )) |
---|
65 | done |
---|
66 | relpath=${relpath}/${lpath} |
---|
67 | fi |
---|
68 | #echo "relpath ${relpath}" |
---|
69 | sed -e "${line}s+\(<pro>\)\([^<]*\)\(</pro>\)+<a href=\"${relpath}/\\2.html\">\2</a>+g" \ |
---|
70 | ${file_html} > ${file_html}_modify |
---|
71 | mv ${file_html}_modify ${file_html} |
---|
72 | fi |
---|
73 | done |
---|
74 | done |
---|
75 | fi |
---|
76 | exit 0 |
---|