[1326] | 1 | #!/bin/ksh |
---|
| 2 | #------------------------------------------------------------------------------# |
---|
| 3 | # This file is part of PALM. |
---|
| 4 | # |
---|
| 5 | # PALM is free software: you can redistribute it and/or modify it under the |
---|
| 6 | # terms of the GNU General Public License as published by the Free Software |
---|
| 7 | # Foundation, either version 3 of the License, or (at your option) any later |
---|
| 8 | # version. |
---|
| 9 | # |
---|
| 10 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | # |
---|
| 14 | # You should have received a copy of the GNU General Public License along with |
---|
| 15 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | # |
---|
[2117] | 17 | # Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
[1326] | 18 | #------------------------------------------------------------------------------# |
---|
| 19 | # |
---|
| 20 | # Current revisions: |
---|
| 21 | # ----------------- |
---|
| 22 | # |
---|
[1828] | 23 | # |
---|
[1326] | 24 | # Former revisions: |
---|
| 25 | # ----------------- |
---|
| 26 | # $Id: document_changes 2117 2017-01-16 16:28:44Z suehring $ |
---|
[1813] | 27 | # |
---|
[1828] | 28 | # 1827 2016-04-07 12:12:23Z maronga |
---|
| 29 | # Added note that the script does not work on MAC OS |
---|
| 30 | # |
---|
[1814] | 31 | # 1813 2016-04-06 09:38:56Z maronga |
---|
| 32 | # Added update of the copyright statements in the file headers. |
---|
| 33 | # |
---|
[1811] | 34 | # 1810 2016-04-05 20:25:29Z maronga |
---|
| 35 | # document_changes now checks all subdirectories. Modified printing to screen. |
---|
| 36 | # |
---|
[1805] | 37 | # 1804 2016-04-05 16:30:18Z maronga |
---|
| 38 | # Removed printing of "this is an alpha version" |
---|
| 39 | # |
---|
[1328] | 40 | # 1326 2014-03-21 10:44:31Z maronga |
---|
| 41 | # Initial revision |
---|
| 42 | # |
---|
[1326] | 43 | # Description: |
---|
| 44 | # ------------ |
---|
| 45 | # This tool moves text from "Current Revisions:" to "Former Revisions:" and |
---|
| 46 | # adds the svn timestamp. It works with the folders SOURCE and SCRIPTS |
---|
| 47 | # |
---|
| 48 | # Usage: |
---|
[1810] | 49 | # a) go to the source directory (e.g. current_version/trunk and perform: |
---|
| 50 | # "document_changes", |
---|
[1326] | 51 | # b) or call "document_changes" directly and add the path to the source code as |
---|
| 52 | # argument |
---|
[1810] | 53 | # (e.g. document_changes trunk) |
---|
[1326] | 54 | # |
---|
| 55 | # Note: |
---|
| 56 | # The script will only work properly if the two following conditions are met: |
---|
| 57 | # 1) the 2nd line after "Current Revisions:" must contain text, |
---|
| 58 | # 2) the last line before "Former Revisions:" must not contain text. |
---|
| 59 | #------------------------------------------------------------------------------# |
---|
| 60 | |
---|
| 61 | # |
---|
| 62 | #-- define variables |
---|
| 63 | comments="" #: variable contains the CR text |
---|
| 64 | comment_char=="!" #: comment character |
---|
| 65 | count_changes=0 #: count the number of files with CR text |
---|
[1813] | 66 | count_updates=0 #: count the number of files with copyright update |
---|
[1326] | 67 | count_files=0 #: count the number of files |
---|
[1810] | 68 | fn="" #: current file name to be scanned |
---|
[1326] | 69 | file_firstchar="" #: first character of filename |
---|
| 70 | file_lastchar="" #: last character of filename |
---|
| 71 | file_extension="" #: filename extension |
---|
| 72 | found_comment=false #: true/false if a CR text was found |
---|
| 73 | IFS='' #: set standard delimiter to empty string |
---|
| 74 | input_dir="" #: directory of the source code |
---|
| 75 | line="" #: containts the current line of filename |
---|
| 76 | line_count=0 #: counter to the line no. of the file |
---|
| 77 | line_start=9999999 #: line no. where CR text starts |
---|
[1810] | 78 | line_stop=0 #: line no. where CR text ends |
---|
[1326] | 79 | line_tmp="" #: first 19 characters of line |
---|
| 80 | list_delete="" #: contains the line no. that must be deleted from CR |
---|
| 81 | timestamp="" #: the svn timestamp of the file |
---|
[1813] | 82 | current_year=$(date +"%Y") |
---|
[1326] | 83 | |
---|
| 84 | # |
---|
| 85 | #-- get input directory |
---|
| 86 | input_dir=$1 |
---|
| 87 | if [[ "$input_dir" == "" ]] |
---|
| 88 | then |
---|
| 89 | input_dir=`pwd` |
---|
| 90 | fi |
---|
[1810] | 91 | |
---|
| 92 | printf "\n" |
---|
| 93 | printf "#------------------------------------------------------------------------# \n" |
---|
| 94 | printf "| \e[1mdocument_changes\e[0m | \n" |
---|
| 95 | printf "| | \n" |
---|
| 96 | printf "| This tool moves the change comments in the all PALM file headers from | \n" |
---|
| 97 | printf "| 'Current revisions' to 'Former revisions' and saves the time stamp. | \n" |
---|
| 98 | printf "#------------------------------------------------------------------------# \n" |
---|
| 99 | |
---|
| 100 | printf "\n *** Checking files in $input_dir and all recursive subdirectories...\n" |
---|
[1326] | 101 | |
---|
[1813] | 102 | |
---|
| 103 | # |
---|
| 104 | #-- scan all (sub-)directories for files. |
---|
[1810] | 105 | IFS=$'\n'; |
---|
[1813] | 106 | for fn in $(find $input_dir -not -name '*.pdf' -and -not -name '*.x' \ |
---|
| 107 | -and -not -name '*.eps' -and -not -name '*.png' \ |
---|
| 108 | -and -not -name '*.svn*' -and -not -name '*~' \ |
---|
| 109 | -and -not -name '*.tar'); do |
---|
[1326] | 110 | |
---|
| 111 | # |
---|
[1813] | 112 | #-- exclude invisible files |
---|
[1810] | 113 | file_firstchar=${fn:0:1} |
---|
| 114 | file_lastchar=`echo -n $fn| tail -c -1` |
---|
| 115 | file_extension=${fn##*.} |
---|
[1813] | 116 | if [[ "$file_firstchar" == "." ]] |
---|
[1326] | 117 | then |
---|
| 118 | continue |
---|
| 119 | fi |
---|
[1810] | 120 | |
---|
[1326] | 121 | (( count_files = count_files + 1 )) |
---|
| 122 | |
---|
| 123 | line_count=0 |
---|
| 124 | found_comment=false |
---|
| 125 | list_delete="" |
---|
| 126 | line_start=9999999 |
---|
| 127 | line_stop=0 |
---|
| 128 | comments="" |
---|
| 129 | |
---|
| 130 | # |
---|
[1813] | 131 | #-- read one line at a time and move revision comments |
---|
[1326] | 132 | while read line |
---|
| 133 | do |
---|
| 134 | |
---|
| 135 | (( line_count = line_count + 1 )) |
---|
| 136 | line_tmp="" |
---|
| 137 | line_tmp=${line:2:17} |
---|
| 138 | |
---|
| 139 | # |
---|
| 140 | #-- check if stopping point is reached |
---|
| 141 | if [[ $line_stop -eq 0 && "$line_tmp" == "Former revisions:" ]] |
---|
| 142 | then |
---|
| 143 | line_stop=$line_count |
---|
| 144 | fi |
---|
| 145 | |
---|
| 146 | # |
---|
| 147 | #-- check if starting point is reached |
---|
| 148 | if [[ $line_start -eq 9999999 && "$line_tmp" == "Current revisions" ]] |
---|
| 149 | then |
---|
| 150 | (( line_start = line_count + 2 )) |
---|
| 151 | comment_char=${line:0:1} |
---|
| 152 | fi |
---|
| 153 | |
---|
| 154 | # |
---|
| 155 | #-- read comment line |
---|
| 156 | if [[ $line_count -ge $line_start && $line_stop -eq 0 ]] |
---|
| 157 | then |
---|
| 158 | |
---|
| 159 | # |
---|
| 160 | #-- check for empty comments |
---|
[1328] | 161 | line_no_space=`echo ${line:2:10} | sed -e 's/^[ \t]*//'` |
---|
| 162 | if [[ $line_count -eq $line_start && "$line_no_space" != "" ]] |
---|
[1326] | 163 | then |
---|
[1810] | 164 | |
---|
| 165 | |
---|
| 166 | printf "\r%$(tput cols)s" " " |
---|
| 167 | printf "\r \e[1;92m*** Comments found in $fn\e[0m\n" |
---|
| 168 | |
---|
[1326] | 169 | found_comment=true |
---|
[1810] | 170 | cp $fn $fn~ |
---|
[1326] | 171 | fi |
---|
| 172 | |
---|
| 173 | # |
---|
| 174 | #-- when comments are found, save comment lines to $comments |
---|
| 175 | if [[ "$found_comment" == true ]] |
---|
| 176 | then |
---|
| 177 | comments="$comments\n$line" |
---|
| 178 | list_delete="$list_delete;${line_count}d" |
---|
| 179 | fi |
---|
| 180 | fi |
---|
[1810] | 181 | |
---|
[1326] | 182 | # |
---|
| 183 | #-- get the timestamp from the current revision |
---|
| 184 | if [[ "$comments" != "" && $line_count -eq $line_stop+2 ]] |
---|
| 185 | then |
---|
| 186 | timestamp=`echo $line | cut -d" " -s -f4-7` |
---|
| 187 | comments="$comment_char $timestamp$comments" |
---|
| 188 | fi |
---|
| 189 | |
---|
[1810] | 190 | done <"$fn" |
---|
[1326] | 191 | |
---|
[1813] | 192 | |
---|
| 193 | |
---|
| 194 | # |
---|
| 195 | #-- check for updates of the copyright statement |
---|
| 196 | found_update_year=false |
---|
| 197 | |
---|
| 198 | while read line |
---|
| 199 | do |
---|
| 200 | |
---|
| 201 | line_tmp="" |
---|
| 202 | line_tmp2="" |
---|
| 203 | line_tmp=${line:22:29} |
---|
| 204 | line_tmp2=${line:2:15} |
---|
| 205 | |
---|
| 206 | # echo "$line_tmp $line_tmp2" |
---|
| 207 | |
---|
| 208 | if [[ "$line_tmp" == "Leibniz Universitaet Hannover" && "$line_tmp2" == "Copyright 1997-" ]] |
---|
| 209 | then |
---|
| 210 | |
---|
| 211 | year_in_file=${line:17:4} |
---|
| 212 | if [[ "$year_in_file" != "$current_year" ]] |
---|
| 213 | then |
---|
| 214 | |
---|
| 215 | printf "\r%$(tput cols)s" " " |
---|
| 216 | printf "\r \e[1;33m*** Copyright update required in $fn\e[0m\n" |
---|
| 217 | |
---|
| 218 | comment_char=${line:0:1} |
---|
| 219 | found_update_year=true |
---|
| 220 | cp $fn $fn~ |
---|
| 221 | |
---|
| 222 | fi |
---|
| 223 | fi |
---|
| 224 | |
---|
| 225 | done <"$fn" |
---|
| 226 | |
---|
[1810] | 227 | printf "\r%$(tput cols)s" " " |
---|
[1813] | 228 | printf "\r\e[1m *** Searched files: $count_files. Comments found: $count_changes. Copyright updates found: $count_updates\e[0m" |
---|
[1810] | 229 | |
---|
[1326] | 230 | # |
---|
| 231 | #-- move comments from current revisions to former revisions |
---|
| 232 | if [[ "$found_comment" == true ]] |
---|
| 233 | then |
---|
| 234 | |
---|
| 235 | (( count_changes = count_changes + 1 )) |
---|
| 236 | |
---|
| 237 | # |
---|
| 238 | #-- insert comments to Former Revisions |
---|
| 239 | (( line_stop = line_stop + 4 )) |
---|
[1810] | 240 | sed -i "${line_stop}i$comments" $fn |
---|
[1326] | 241 | |
---|
| 242 | # |
---|
| 243 | #-- delete comments from current revisions and insert two blank lines |
---|
| 244 | list_delete=${list_delete#?} |
---|
[1810] | 245 | sed -i "$list_delete" $fn |
---|
| 246 | sed -i "${line_start}i${comment_char} " $fn |
---|
| 247 | sed -i "${line_start}i${comment_char} " $fn |
---|
[1326] | 248 | |
---|
| 249 | fi |
---|
| 250 | |
---|
[1813] | 251 | # |
---|
| 252 | #-- move comments from current revisions to former revisions |
---|
| 253 | if [[ "$found_update_year" == true ]] |
---|
| 254 | then |
---|
| 255 | |
---|
| 256 | (( count_updates = count_updates + 1 )) |
---|
| 257 | |
---|
| 258 | sed -i "s/$comment_char Copyright 1997-.*Leibniz Universitaet Hannover/$comment_char Copyright 1997-$current_year Leibniz Universitaet Hannover/" $fn |
---|
| 259 | |
---|
| 260 | fi |
---|
| 261 | |
---|
[1326] | 262 | done |
---|
| 263 | |
---|
| 264 | # |
---|
| 265 | #-- inform the user about the changes |
---|
[1810] | 266 | printf "\r%$(tput cols)s" " " |
---|
[1813] | 267 | printf "\r\e[1m *** Searched files: $count_files. Comments found: $count_changes. Copyright updates found: $count_updates\e[0m. - \e[1;32mfinished.\e[0m\n\n" |
---|
[1810] | 268 | |
---|
[1326] | 269 | if [[ $count_changes -gt 0 ]] |
---|
| 270 | then |
---|
[1810] | 271 | printf " *** You can now proceed with\n \e[0;91msvn commit -m 'last commit documented' trunk\e[0m\n" |
---|
| 272 | printf " *** Please do not forget to commit your changes in the changelog at\n \e[0;91mhttps://palm.muk.uni-hannover.de/trac/wiki/doc/tec/changelog\e[0m!\n" |
---|
[1326] | 273 | else |
---|
[1810] | 274 | printf " *** No comments found in files!\n" |
---|
| 275 | |
---|
[1326] | 276 | fi |
---|