[3802] | 1 | #!/bin/bash |
---|
[1326] | 2 | #------------------------------------------------------------------------------# |
---|
[2696] | 3 | # This file is part of the PALM model system. |
---|
[1326] | 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 | # |
---|
[3665] | 17 | # Copyright 1997-2019 Leibniz Universitaet Hannover |
---|
[1326] | 18 | #------------------------------------------------------------------------------# |
---|
| 19 | # |
---|
| 20 | # Current revisions: |
---|
| 21 | # ----------------- |
---|
| 22 | # |
---|
[1828] | 23 | # |
---|
[1326] | 24 | # Former revisions: |
---|
| 25 | # ----------------- |
---|
| 26 | # $Id: document_changes 3802 2019-03-17 13:33:42Z schwenkel $ |
---|
[3802] | 27 | # script made bash compatible |
---|
| 28 | # |
---|
| 29 | # 3665 2019-01-10 08:28:24Z raasch |
---|
[2716] | 30 | # Corrected "Former revisions" section |
---|
| 31 | # |
---|
| 32 | # 2696 2017-12-14 17:12:51Z kanani |
---|
| 33 | # Change in file header (GPL part) |
---|
| 34 | # |
---|
| 35 | # 2235 2017-05-31 08:03:49Z maronga |
---|
[2235] | 36 | # Changed the submission procedure in order to reduce the number of required |
---|
| 37 | # commits to one per change. |
---|
[1813] | 38 | # |
---|
[2235] | 39 | # 2117 2017-01-16 16:28:44Z maronga |
---|
| 40 | # |
---|
[1828] | 41 | # 1827 2016-04-07 12:12:23Z maronga |
---|
| 42 | # Added note that the script does not work on MAC OS |
---|
| 43 | # |
---|
[1814] | 44 | # 1813 2016-04-06 09:38:56Z maronga |
---|
| 45 | # Added update of the copyright statements in the file headers. |
---|
| 46 | # |
---|
[1811] | 47 | # 1810 2016-04-05 20:25:29Z maronga |
---|
| 48 | # document_changes now checks all subdirectories. Modified printing to screen. |
---|
| 49 | # |
---|
[1805] | 50 | # 1804 2016-04-05 16:30:18Z maronga |
---|
| 51 | # Removed printing of "this is an alpha version" |
---|
| 52 | # |
---|
[1328] | 53 | # 1326 2014-03-21 10:44:31Z maronga |
---|
| 54 | # Initial revision |
---|
| 55 | # |
---|
[1326] | 56 | # Description: |
---|
| 57 | # ------------ |
---|
| 58 | # This tool moves text from "Current Revisions:" to "Former Revisions:" and |
---|
| 59 | # adds the svn timestamp. It works with the folders SOURCE and SCRIPTS |
---|
| 60 | # |
---|
| 61 | # Usage: |
---|
[1810] | 62 | # a) go to the source directory (e.g. current_version/trunk and perform: |
---|
| 63 | # "document_changes", |
---|
[1326] | 64 | # b) or call "document_changes" directly and add the path to the source code as |
---|
| 65 | # argument |
---|
[1810] | 66 | # (e.g. document_changes trunk) |
---|
[1326] | 67 | # |
---|
| 68 | # Note: |
---|
| 69 | # The script will only work properly if the two following conditions are met: |
---|
| 70 | # 1) the 2nd line after "Current Revisions:" must contain text, |
---|
| 71 | # 2) the last line before "Former Revisions:" must not contain text. |
---|
| 72 | #------------------------------------------------------------------------------# |
---|
| 73 | |
---|
| 74 | # |
---|
| 75 | #-- define variables |
---|
| 76 | comments="" #: variable contains the CR text |
---|
| 77 | comment_char=="!" #: comment character |
---|
| 78 | count_changes=0 #: count the number of files with CR text |
---|
[1813] | 79 | count_updates=0 #: count the number of files with copyright update |
---|
[1326] | 80 | count_files=0 #: count the number of files |
---|
[1810] | 81 | fn="" #: current file name to be scanned |
---|
[1326] | 82 | file_firstchar="" #: first character of filename |
---|
| 83 | file_lastchar="" #: last character of filename |
---|
| 84 | file_extension="" #: filename extension |
---|
| 85 | found_comment=false #: true/false if a CR text was found |
---|
| 86 | IFS='' #: set standard delimiter to empty string |
---|
| 87 | input_dir="" #: directory of the source code |
---|
| 88 | line="" #: containts the current line of filename |
---|
| 89 | line_count=0 #: counter to the line no. of the file |
---|
| 90 | line_start=9999999 #: line no. where CR text starts |
---|
[1810] | 91 | line_stop=0 #: line no. where CR text ends |
---|
[1326] | 92 | line_tmp="" #: first 19 characters of line |
---|
| 93 | list_delete="" #: contains the line no. that must be deleted from CR |
---|
| 94 | timestamp="" #: the svn timestamp of the file |
---|
[1813] | 95 | current_year=$(date +"%Y") |
---|
[1326] | 96 | |
---|
| 97 | # |
---|
| 98 | #-- get input directory |
---|
| 99 | input_dir=$1 |
---|
| 100 | if [[ "$input_dir" == "" ]] |
---|
| 101 | then |
---|
| 102 | input_dir=`pwd` |
---|
| 103 | fi |
---|
[1810] | 104 | |
---|
| 105 | printf "\n" |
---|
| 106 | printf "#------------------------------------------------------------------------# \n" |
---|
| 107 | printf "| \e[1mdocument_changes\e[0m | \n" |
---|
| 108 | printf "| | \n" |
---|
| 109 | printf "| This tool moves the change comments in the all PALM file headers from | \n" |
---|
| 110 | printf "| 'Current revisions' to 'Former revisions' and saves the time stamp. | \n" |
---|
| 111 | printf "#------------------------------------------------------------------------# \n" |
---|
| 112 | |
---|
| 113 | printf "\n *** Checking files in $input_dir and all recursive subdirectories...\n" |
---|
[1326] | 114 | |
---|
[1813] | 115 | |
---|
| 116 | # |
---|
| 117 | #-- scan all (sub-)directories for files. |
---|
[1810] | 118 | IFS=$'\n'; |
---|
[1813] | 119 | for fn in $(find $input_dir -not -name '*.pdf' -and -not -name '*.x' \ |
---|
| 120 | -and -not -name '*.eps' -and -not -name '*.png' \ |
---|
| 121 | -and -not -name '*.svn*' -and -not -name '*~' \ |
---|
[3802] | 122 | -and -not -name '*.tar' -and -not -type d ); do |
---|
[1326] | 123 | |
---|
| 124 | # |
---|
[1813] | 125 | #-- exclude invisible files |
---|
[1810] | 126 | file_firstchar=${fn:0:1} |
---|
| 127 | file_lastchar=`echo -n $fn| tail -c -1` |
---|
| 128 | file_extension=${fn##*.} |
---|
[1813] | 129 | if [[ "$file_firstchar" == "." ]] |
---|
[1326] | 130 | then |
---|
| 131 | continue |
---|
| 132 | fi |
---|
[1810] | 133 | |
---|
[1326] | 134 | (( count_files = count_files + 1 )) |
---|
| 135 | |
---|
| 136 | line_count=0 |
---|
| 137 | found_comment=false |
---|
| 138 | list_delete="" |
---|
| 139 | line_start=9999999 |
---|
| 140 | line_stop=0 |
---|
| 141 | comments="" |
---|
| 142 | |
---|
| 143 | # |
---|
[1813] | 144 | #-- read one line at a time and move revision comments |
---|
[1326] | 145 | while read line |
---|
| 146 | do |
---|
| 147 | |
---|
| 148 | (( line_count = line_count + 1 )) |
---|
| 149 | line_tmp="" |
---|
| 150 | line_tmp=${line:2:17} |
---|
| 151 | |
---|
| 152 | # |
---|
| 153 | #-- check if stopping point is reached |
---|
| 154 | if [[ $line_stop -eq 0 && "$line_tmp" == "Former revisions:" ]] |
---|
| 155 | then |
---|
| 156 | line_stop=$line_count |
---|
| 157 | fi |
---|
| 158 | |
---|
| 159 | # |
---|
| 160 | #-- check if starting point is reached |
---|
| 161 | if [[ $line_start -eq 9999999 && "$line_tmp" == "Current revisions" ]] |
---|
| 162 | then |
---|
| 163 | (( line_start = line_count + 2 )) |
---|
| 164 | comment_char=${line:0:1} |
---|
| 165 | fi |
---|
| 166 | |
---|
| 167 | # |
---|
| 168 | #-- read comment line |
---|
| 169 | if [[ $line_count -ge $line_start && $line_stop -eq 0 ]] |
---|
| 170 | then |
---|
| 171 | |
---|
| 172 | # |
---|
| 173 | #-- check for empty comments |
---|
[1328] | 174 | line_no_space=`echo ${line:2:10} | sed -e 's/^[ \t]*//'` |
---|
| 175 | if [[ $line_count -eq $line_start && "$line_no_space" != "" ]] |
---|
[1326] | 176 | then |
---|
[1810] | 177 | |
---|
| 178 | |
---|
| 179 | printf "\r%$(tput cols)s" " " |
---|
| 180 | printf "\r \e[1;92m*** Comments found in $fn\e[0m\n" |
---|
| 181 | |
---|
[1326] | 182 | found_comment=true |
---|
[1810] | 183 | cp $fn $fn~ |
---|
[1326] | 184 | fi |
---|
| 185 | |
---|
| 186 | # |
---|
| 187 | #-- when comments are found, save comment lines to $comments |
---|
| 188 | if [[ "$found_comment" == true ]] |
---|
| 189 | then |
---|
| 190 | comments="$comments\n$line" |
---|
| 191 | list_delete="$list_delete;${line_count}d" |
---|
| 192 | fi |
---|
| 193 | fi |
---|
[1810] | 194 | |
---|
[1326] | 195 | # |
---|
| 196 | #-- get the timestamp from the current revision |
---|
| 197 | if [[ "$comments" != "" && $line_count -eq $line_stop+2 ]] |
---|
| 198 | then |
---|
[2235] | 199 | comments="$comment_char $line$comments" |
---|
[1326] | 200 | timestamp=`echo $line | cut -d" " -s -f4-7` |
---|
[2235] | 201 | timestamp_string="$comment_char $timestamp" |
---|
[1326] | 202 | fi |
---|
[2235] | 203 | |
---|
[1810] | 204 | done <"$fn" |
---|
[1326] | 205 | |
---|
[1813] | 206 | |
---|
| 207 | |
---|
| 208 | # |
---|
| 209 | #-- check for updates of the copyright statement |
---|
| 210 | found_update_year=false |
---|
| 211 | |
---|
| 212 | while read line |
---|
| 213 | do |
---|
| 214 | |
---|
| 215 | line_tmp="" |
---|
| 216 | line_tmp2="" |
---|
| 217 | line_tmp=${line:22:29} |
---|
| 218 | line_tmp2=${line:2:15} |
---|
| 219 | |
---|
| 220 | # echo "$line_tmp $line_tmp2" |
---|
| 221 | |
---|
| 222 | if [[ "$line_tmp" == "Leibniz Universitaet Hannover" && "$line_tmp2" == "Copyright 1997-" ]] |
---|
| 223 | then |
---|
| 224 | |
---|
| 225 | year_in_file=${line:17:4} |
---|
| 226 | if [[ "$year_in_file" != "$current_year" ]] |
---|
| 227 | then |
---|
| 228 | |
---|
| 229 | printf "\r%$(tput cols)s" " " |
---|
| 230 | printf "\r \e[1;33m*** Copyright update required in $fn\e[0m\n" |
---|
| 231 | |
---|
| 232 | comment_char=${line:0:1} |
---|
| 233 | found_update_year=true |
---|
| 234 | cp $fn $fn~ |
---|
| 235 | |
---|
| 236 | fi |
---|
| 237 | fi |
---|
| 238 | |
---|
| 239 | done <"$fn" |
---|
| 240 | |
---|
[1810] | 241 | printf "\r%$(tput cols)s" " " |
---|
[1813] | 242 | printf "\r\e[1m *** Searched files: $count_files. Comments found: $count_changes. Copyright updates found: $count_updates\e[0m" |
---|
[1810] | 243 | |
---|
[1326] | 244 | # |
---|
| 245 | #-- move comments from current revisions to former revisions |
---|
| 246 | if [[ "$found_comment" == true ]] |
---|
| 247 | then |
---|
| 248 | |
---|
| 249 | (( count_changes = count_changes + 1 )) |
---|
| 250 | |
---|
| 251 | # |
---|
[2235] | 252 | #-- remove leading \n characters in string |
---|
| 253 | comments=${comments:2} |
---|
| 254 | |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | # |
---|
| 258 | #-- fix old time stamp |
---|
| 259 | (( line_time = line_stop + 2 )) |
---|
| 260 | sed -i "${line_time}d" $fn |
---|
| 261 | sed -i "${line_time}i$timestamp_string" $fn |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | # |
---|
[1326] | 266 | #-- insert comments to Former Revisions |
---|
[2235] | 267 | (( line_stop = line_stop + 2 )) |
---|
[1810] | 268 | sed -i "${line_stop}i$comments" $fn |
---|
[2235] | 269 | |
---|
[1326] | 270 | |
---|
[2235] | 271 | |
---|
[1326] | 272 | # |
---|
| 273 | #-- delete comments from current revisions and insert two blank lines |
---|
| 274 | list_delete=${list_delete#?} |
---|
[1810] | 275 | sed -i "$list_delete" $fn |
---|
| 276 | sed -i "${line_start}i${comment_char} " $fn |
---|
| 277 | sed -i "${line_start}i${comment_char} " $fn |
---|
[1326] | 278 | |
---|
| 279 | fi |
---|
| 280 | |
---|
[1813] | 281 | # |
---|
| 282 | #-- move comments from current revisions to former revisions |
---|
| 283 | if [[ "$found_update_year" == true ]] |
---|
| 284 | then |
---|
| 285 | |
---|
| 286 | (( count_updates = count_updates + 1 )) |
---|
| 287 | |
---|
| 288 | sed -i "s/$comment_char Copyright 1997-.*Leibniz Universitaet Hannover/$comment_char Copyright 1997-$current_year Leibniz Universitaet Hannover/" $fn |
---|
| 289 | |
---|
| 290 | fi |
---|
| 291 | |
---|
[1326] | 292 | done |
---|
| 293 | |
---|
| 294 | # |
---|
| 295 | #-- inform the user about the changes |
---|
[1810] | 296 | printf "\r%$(tput cols)s" " " |
---|
[1813] | 297 | 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] | 298 | |
---|
[1326] | 299 | if [[ $count_changes -gt 0 ]] |
---|
| 300 | then |
---|
[2235] | 301 | printf " *** You can now proceed with\n \e[0;91msvn commit -m 'your commit message' trunk\e[0m\n" |
---|
[1810] | 302 | 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] | 303 | else |
---|
[1810] | 304 | printf " *** No comments found in files!\n" |
---|
| 305 | |
---|
[1326] | 306 | fi |
---|