source: palm/trunk/SCRIPTS/document_changes @ 4732

Last change on this file since 4732 was 4586, checked in by gronemeier, 4 years ago

renamed Richardson flux number into gradient Richardson number (model_1d_mod.f90, turbulence_closure_mod.f90, header.f90, surface_mod.f90) and zeta (header.f90);
do not add whitespaces at current-revision section (document_changes)

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