[233] | 1 | #! /bin/sh |
---|
| 2 | # |
---|
[415] | 3 | # DESCRIPTION |
---|
[431] | 4 | # =========== |
---|
[415] | 5 | # |
---|
[262] | 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 |
---|
[431] | 9 | # We have to deal with the path of ginette.html in refhtml also given in |
---|
[262] | 10 | # argument. |
---|
| 11 | # |
---|
[233] | 12 | # see call in savesaxo.sh |
---|
| 13 | # |
---|
[415] | 14 | # EVOLUTIONS |
---|
| 15 | # ========== |
---|
[233] | 16 | # $Id$ |
---|
[415] | 17 | # |
---|
[262] | 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> |
---|
[431] | 21 | # add -i parameter : this directory is the one where we are looking for |
---|
[262] | 22 | # html files to be modified. so replace output by dirhtml |
---|
[431] | 23 | # add -r parameter : this directory is the one where we are looking for |
---|
[262] | 24 | # html files to be linked |
---|
[431] | 25 | # remove lowercase translation (because of idl help files which are in |
---|
[262] | 26 | # uppercase) |
---|
[259] | 27 | # fplod 2007-08-20T11:25:39Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
[262] | 28 | # correction from |
---|
[259] | 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 |
---|
[262] | 31 | #++ still not working perfectly because path of links on the different occurences of <pro>...</pro> may not be the same |
---|
[253] | 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 |
---|
[262] | 35 | # see http://www.gentoo.org/doc/en/articles/l-sed2.xml |
---|
[253] | 36 | # Sed by example, Part 2 |
---|
| 37 | # especially for directory-overview files |
---|
[233] | 38 | # fplod 2007-03-20T14:02:14Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 39 | # creation |
---|
| 40 | # |
---|
[262] | 41 | set -o posix |
---|
| 42 | command=$(basename ${0} .sh) |
---|
[415] | 43 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
[262] | 44 | log=/tmp/${command}.${log_date} |
---|
| 45 | # |
---|
| 46 | usage=" Usage : ${command} -i dirhtml -r refhtml -e element" |
---|
| 47 | # |
---|
[437] | 48 | set +u |
---|
[262] | 49 | while [ ! -z "${1}" ] |
---|
| 50 | do |
---|
[430] | 51 | case ${1} in |
---|
[431] | 52 | -i) |
---|
[430] | 53 | dirhtml=${2} |
---|
| 54 | shift |
---|
| 55 | ;; |
---|
[431] | 56 | -r) |
---|
[430] | 57 | refhtml=${2} |
---|
| 58 | shift |
---|
| 59 | ;; |
---|
[431] | 60 | -e) |
---|
[430] | 61 | element=${2} |
---|
| 62 | shift |
---|
| 63 | ;; |
---|
| 64 | -h) |
---|
| 65 | echo "${usage}" |
---|
| 66 | exit 0 |
---|
| 67 | ;; |
---|
[431] | 68 | *) |
---|
| 69 | # other choice |
---|
[430] | 70 | echo "${usage}" |
---|
| 71 | exit 1 |
---|
| 72 | ;; |
---|
| 73 | esac |
---|
[431] | 74 | # next flag |
---|
| 75 | shift |
---|
[262] | 76 | done |
---|
| 77 | # |
---|
[233] | 78 | set -u |
---|
| 79 | # |
---|
[262] | 80 | # check for dirhtml |
---|
| 81 | if [ ! -d ${dirhtml} ] |
---|
[233] | 82 | then |
---|
[262] | 83 | echo "eee : ${dirhtml} not found" |
---|
| 84 | exit 1 |
---|
| 85 | fi |
---|
| 86 | # ++ check for readable/writable |
---|
| 87 | # |
---|
| 88 | # check for refhtml |
---|
| 89 | if [ ! -d ${refhtml} ] |
---|
| 90 | then |
---|
| 91 | echo "eee : ${refhtml} not found" |
---|
| 92 | exit 1 |
---|
| 93 | fi |
---|
| 94 | # ++ check for readable |
---|
| 95 | # |
---|
| 96 | # check for element |
---|
| 97 | if [ "${element}" == "" ] |
---|
| 98 | then |
---|
| 99 | echo "eee : ${element} empty" |
---|
| 100 | exit 1 |
---|
| 101 | fi |
---|
| 102 | # |
---|
| 103 | # first find all files containing <element>...</element> |
---|
| 104 | list_html_element=$(find ${dirhtml} -name "*.html" -exec grep -l "<${element}>.*</${element}>" {} \;) |
---|
| 105 | if [ "${list_html_element}" == "" ] |
---|
| 106 | then |
---|
| 107 | echo "iii : no <${element}>...</${element}> in html files" |
---|
[233] | 108 | else |
---|
[262] | 109 | for file_html in ${list_html_element} |
---|
[233] | 110 | do |
---|
[420] | 111 | #echo "file_html ${file_html}" |
---|
| 112 | #read a |
---|
[430] | 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 |
---|
[431] | 141 | if [ "${lpath:0:1}" = "/" ] |
---|
[430] | 142 | then |
---|
[431] | 143 | # absolute path |
---|
[430] | 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 |
---|
[259] | 159 | 1{x;s@^@first@;x;} |
---|
[262] | 160 | 1,/<${element}>${link}<\/${element}>/{x;/first/s///;x;s@<${element}>${link}<\/${element}>@<a href="${path}/${link}.html">${link}<\/a>@;} |
---|
[259] | 161 | EOF |
---|
[430] | 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 |
---|
[233] | 170 | done |
---|
| 171 | fi |
---|
| 172 | exit 0 |
---|