source: palm/trunk/SCRIPTS/document_changes @ 1813

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

extented document_changes for updating the copyright statement in the file headers

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