source: palm/trunk/SCRIPTS/document_changes @ 2799

Last change on this file since 2799 was 2718, checked in by maronga, 7 years ago

deleting of deprecated files; headers updated where needed

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