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