source: palm/trunk/SCRIPTS/document_changes @ 2699

Last change on this file since 2699 was 2696, checked in by kanani, 7 years ago

Merge of branch palm4u into trunk

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