source: palm/trunk/SCRIPTS/document_changes @ 1846

Last change on this file since 1846 was 1828, checked in by maronga, 9 years ago

last commit documented

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