source: palm/trunk/SCRIPTS/document_changes @ 4151

Last change on this file since 4151 was 3802, checked in by raasch, 6 years ago

unused variables removed, unused subroutines commented out, type conversion added to avoid compiler warning about constant integer division truncation, script document_changes made bash compatible

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
1#!/bin/bash
2#------------------------------------------------------------------------------#
3# This file is part of the PALM model system.
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-2019 Leibniz Universitaet Hannover
18#------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22#
23#
24# Former revisions:
25# -----------------
26# $Id: document_changes 3802 2019-03-17 13:33:42Z suehring $
27# script made bash compatible
28#
29# 3665 2019-01-10 08:28:24Z raasch
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
36# Changed the submission procedure in order to reduce the number of required
37# commits to one per change.
38#
39# 2117 2017-01-16 16:28:44Z maronga
40#
41# 1827 2016-04-07 12:12:23Z maronga
42# Added note that the script does not work on MAC OS
43#
44# 1813 2016-04-06 09:38:56Z maronga
45# Added update of the copyright statements in the file headers.
46#
47# 1810 2016-04-05 20:25:29Z maronga
48# document_changes now checks all subdirectories. Modified printing to screen.
49#
50# 1804 2016-04-05 16:30:18Z maronga
51# Removed printing of "this is an alpha version"
52#
53# 1326 2014-03-21 10:44:31Z maronga
54# Initial revision
55#
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:
62# a) go to the source directory (e.g. current_version/trunk and perform:
63#    "document_changes",
64# b) or call "document_changes" directly and add the path to the source code as
65#    argument
66#    (e.g. document_changes trunk)
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
79    count_updates=0     #: count the number of files with copyright update
80    count_files=0       #: count the number of files
81    fn=""               #: current file name to be scanned
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
91    line_stop=0         #: line no. where CR text ends
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
95    current_year=$(date +"%Y")
96
97#
98#-- get input directory
99    input_dir=$1
100    if  [[ "$input_dir" == "" ]]
101    then
102       input_dir=`pwd`
103    fi
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"
114
115   
116#
117#-- scan all (sub-)directories for files.
118    IFS=$'\n';
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 '*~'       \
122                           -and -not -name '*.tar'  -and -not -type d ); do
123
124#
125#--    exclude invisible files
126       file_firstchar=${fn:0:1}
127       file_lastchar=`echo -n $fn| tail -c -1`
128       file_extension=${fn##*.}
129       if [[ "$file_firstchar" == "." ]]
130       then
131          continue
132       fi
133       
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#
144#--    read one line at a time and move revision comments
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
174             line_no_space=`echo ${line:2:10} | sed -e 's/^[ \t]*//'`
175             if [[ $line_count -eq $line_start && "$line_no_space" != "" ]]
176             then
177
178             
179                printf "\r%$(tput cols)s" " "   
180                printf "\r  \e[1;92m*** Comments found in $fn\e[0m\n"
181             
182                found_comment=true
183                cp $fn $fn~
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
194         
195#
196#--       get the timestamp from the current revision
197          if [[ "$comments" != "" && $line_count -eq $line_stop+2 ]]
198          then
199            comments="$comment_char $line$comments"
200            timestamp=`echo $line | cut -d" " -s -f4-7`
201            timestamp_string="$comment_char $timestamp"
202          fi
203         
204       done <"$fn"
205
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         
241       printf "\r%$(tput cols)s" " "   
242       printf "\r\e[1m  *** Searched files: $count_files. Comments found: $count_changes. Copyright updates found: $count_updates\e[0m"
243       
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#
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#
266#--       insert comments to Former Revisions
267          (( line_stop = line_stop + 2 ))
268          sed -i "${line_stop}i$comments" $fn
269         
270
271
272#
273#--       delete comments from current revisions and insert two blank lines
274          list_delete=${list_delete#?}
275          sed -i "$list_delete" $fn
276          sed -i "${line_start}i${comment_char} " $fn
277          sed -i "${line_start}i${comment_char} " $fn
278
279       fi
280
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       
292    done
293
294#
295#-- inform the user about the changes
296    printf "\r%$(tput cols)s" " "
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"
298
299    if  [[ $count_changes -gt 0 ]]
300    then
301       printf "  *** You can now proceed with\n      \e[0;91msvn commit -m 'your commit message' trunk\e[0m\n"
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"   
303    else
304        printf "  *** No comments found in files!\n"   
305   
306    fi
Note: See TracBrowser for help on using the repository browser.