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