source: palm/trunk/SCRIPTS/document_changes @ 1814

Last change on this file since 1814 was 1814, checked in by maronga, 6 years ago

last commit documented

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