[233] | 1 | #! /bin/sh |
---|
| 2 | # |
---|
[262] | 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 | # |
---|
[233] | 10 | # see call in savesaxo.sh |
---|
| 11 | # |
---|
| 12 | # update : |
---|
| 13 | # $Id$ |
---|
[262] | 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) |
---|
[259] | 23 | # fplod 2007-08-20T11:25:39Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
[262] | 24 | # correction from |
---|
[259] | 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 |
---|
[262] | 27 | #++ still not working perfectly because path of links on the different occurences of <pro>...</pro> may not be the same |
---|
[253] | 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 |
---|
[262] | 31 | # see http://www.gentoo.org/doc/en/articles/l-sed2.xml |
---|
[253] | 32 | # Sed by example, Part 2 |
---|
| 33 | # especially for directory-overview files |
---|
[233] | 34 | # fplod 2007-03-20T14:02:14Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 35 | # creation |
---|
| 36 | # |
---|
[262] | 37 | set -o posix |
---|
| 38 | command=$(basename ${0} .sh) |
---|
| 39 | log_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
---|
| 40 | log=/tmp/${command}.${log_date} |
---|
| 41 | # |
---|
| 42 | usage=" Usage : ${command} -i dirhtml -r refhtml -e element" |
---|
| 43 | # |
---|
| 44 | while [ ! -z "${1}" ] |
---|
| 45 | do |
---|
| 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 |
---|
| 69 | done |
---|
| 70 | # |
---|
[233] | 71 | set -u |
---|
| 72 | # |
---|
[262] | 73 | # check for dirhtml |
---|
| 74 | if [ ! -d ${dirhtml} ] |
---|
[233] | 75 | then |
---|
[262] | 76 | echo "eee : ${dirhtml} not found" |
---|
| 77 | exit 1 |
---|
| 78 | fi |
---|
| 79 | # ++ check for readable/writable |
---|
| 80 | # |
---|
| 81 | # check for refhtml |
---|
| 82 | if [ ! -d ${refhtml} ] |
---|
| 83 | then |
---|
| 84 | echo "eee : ${refhtml} not found" |
---|
| 85 | exit 1 |
---|
| 86 | fi |
---|
| 87 | # ++ check for readable |
---|
| 88 | # |
---|
| 89 | # check for element |
---|
| 90 | if [ "${element}" == "" ] |
---|
| 91 | then |
---|
| 92 | echo "eee : ${element} empty" |
---|
| 93 | exit 1 |
---|
| 94 | fi |
---|
| 95 | # |
---|
| 96 | # first find all files containing <element>...</element> |
---|
| 97 | list_html_element=$(find ${dirhtml} -name "*.html" -exec grep -l "<${element}>.*</${element}>" {} \;) |
---|
| 98 | if [ "${list_html_element}" == "" ] |
---|
| 99 | then |
---|
| 100 | echo "iii : no <${element}>...</${element}> in html files" |
---|
[233] | 101 | else |
---|
[262] | 102 | for file_html in ${list_html_element} |
---|
[233] | 103 | do |
---|
[259] | 104 | # echo "file_html ${file_html}" |
---|
| 105 | # read a |
---|
[262] | 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}>.*$//") |
---|
[259] | 110 | # echo "liste link" ${list_link} |
---|
| 111 | # read a |
---|
| 112 | for link in ${list_link} |
---|
[233] | 113 | do |
---|
[262] | 114 | # replace <element>something</element> by |
---|
[233] | 115 | #<a href="something.html">something</a> |
---|
[259] | 116 | # modulehtml is the html file name to be used |
---|
| 117 | modulehtml=${link}.html |
---|
[233] | 118 | # lpath is the path on module relatively to the location of |
---|
[262] | 119 | # the html file containing the <element>...</element> |
---|
| 120 | lpath=$(find ${refhtml} -name "${modulehtml}") |
---|
[233] | 121 | if [ "${lpath}" = "" ] |
---|
| 122 | then |
---|
[262] | 123 | echo "eee : path of ${modulehtml} not found under ${refhtml}" |
---|
[259] | 124 | echo "eee : ${link} is used in ${file_html}" |
---|
[233] | 125 | else |
---|
[262] | 126 | lpath=$(dirname ${lpath} | sed -e "s+\(${refhtml}/\)\(.*\)+\2+") |
---|
[233] | 127 | #echo "path du fichier html ${fpath}" |
---|
| 128 | #echo "lpath ${lpath}" |
---|
[262] | 129 | #read a |
---|
[233] | 130 | if [ "${lpath}" = "${fpath}" ] |
---|
| 131 | then |
---|
[262] | 132 | path="./" |
---|
| 133 | fi |
---|
| 134 | if [ "${lpath:0:1}" = "/" ] # absolute path |
---|
| 135 | then |
---|
| 136 | path=${lpath} |
---|
[233] | 137 | else |
---|
| 138 | nblev=$(echo ${fpath} | sed -e "s@/\$@@" | awk -F "/" '{print NF}') |
---|
[237] | 139 | relpath="" |
---|
[233] | 140 | ilev=1 |
---|
| 141 | while [ ${ilev} -le ${nblev} ] |
---|
| 142 | do |
---|
[237] | 143 | relpath="${relpath}../" |
---|
[233] | 144 | ilev=$(( ${ilev} + 1 )) |
---|
| 145 | done |
---|
[262] | 146 | path=${relpath}/${lpath} |
---|
[233] | 147 | fi |
---|
[262] | 148 | #echo "path ${path}" |
---|
| 149 | #read a |
---|
[259] | 150 | cat <<EOF > /tmp/pro2href${$}.sed |
---|
| 151 | 1{x;s@^@first@;x;} |
---|
[262] | 152 | 1,/<${element}>${link}<\/${element}>/{x;/first/s///;x;s@<${element}>${link}<\/${element}>@<a href="${path}/${link}.html">${link}<\/a>@;} |
---|
[259] | 153 | EOF |
---|
| 154 | sed -f /tmp/pro2href${$}.sed \ |
---|
[233] | 155 | ${file_html} > ${file_html}_modify |
---|
[262] | 156 | #diff ${file_html} ${file_html}_modify |
---|
| 157 | #read a |
---|
[233] | 158 | mv ${file_html}_modify ${file_html} |
---|
[259] | 159 | rm /tmp/pro2href${$}.sed |
---|
[233] | 160 | fi |
---|
| 161 | done |
---|
| 162 | done |
---|
| 163 | fi |
---|
| 164 | exit 0 |
---|