source: palm/trunk/SCRIPTS/document_changes @ 1326

Last change on this file since 1326 was 1326, checked in by maronga, 10 years ago

added script document_changes

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 6.2 KB
RevLine 
[1326]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-2014  Leibniz Universitaet Hannover
18#------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22# Initial revision
23#
24# Former revisions:
25# -----------------
26# $Id: document_changes 1326 2014-03-21 10:44:31Z maronga $
27#
28# Description:
29# ------------
30# This tool moves text from "Current Revisions:" to "Former Revisions:" and
31# adds the svn timestamp. It works with the folders SOURCE and SCRIPTS
32#
33# Usage:
34# a) go to the source directory (e.g. current_version/trunk/SOURCE and
35#    perform "document_changes",
36# b) or call "document_changes" directly and add the path to the source code as
37#    argument
38#    (e.g. document_changes current_version/trunk/SOURCE)
39#
40# Note:
41# The script will only work properly if the two following conditions are met:
42# 1) the 2nd line after "Current Revisions:" must contain text,
43# 2) the last line before "Former Revisions:" must not contain text.
44#------------------------------------------------------------------------------#
45
46#
47#-- define variables
48    comments=""         #: variable contains the CR text
49    comment_char=="!"   #: comment character
50    count_changes=0     #: count the number of files with CR text
51    count_files=0       #: count the number of files
52    filename=""         #: current file name to be scanned
53    file_firstchar=""   #: first character of filename
54    file_lastchar=""    #: last character of filename
55    file_extension=""   #: filename extension
56    found_comment=false #: true/false if a CR text was found
57    IFS=''              #: set standard delimiter to empty string
58    input_dir=""        #: directory of the source code
59    line=""             #: containts the current line of filename
60    line_count=0        #: counter to the line no. of the file
61    line_start=9999999  #: line no. where CR text starts
62    line_stop=0         #: line no. where Cr text ends
63    line_tmp=""         #: first 19 characters of line
64    list_delete=""      #: contains the line no. that must be deleted from CR
65    timestamp=""        #: the svn timestamp of the file
66
67#
68#-- get input directory
69    input_dir=$1
70    if  [[ "$input_dir" == "" ]]
71    then
72       input_dir=`pwd`
73    fi
74    printf "\n  *** Checking files in $input_dir\n"
75    printf "\n  +++ THIS IS AN ALPHA VERSION. PLEASE CHECK THE MODIFIED FILES BEFORE COMMITTING\n"
76
77    for filename in $input_dir/*; do
78
79#
80#--    exclude backup and invisible files
81       file_firstchar=${filename:0:1}
82       file_lastchar=`echo -n $filename| tail -c -1`
83       file_extension=${filename##*.}
84       if [[ "$file_firstchar" == "." || "$file_extension" == "x" || "$file_lastchar" == "~" || "$file_extension" == "tar" ]]
85       then
86          continue
87       fi
88
89       (( count_files = count_files + 1 ))
90
91       line_count=0
92       found_comment=false
93       list_delete=""
94       line_start=9999999
95       line_stop=0
96       comments=""
97
98#
99#--    read one line at a time
100       while read line
101       do
102
103          (( line_count = line_count + 1 ))
104          line_tmp=""
105          line_tmp=${line:2:17}
106
107#
108#--       check if stopping point is reached
109          if [[ $line_stop -eq 0 && "$line_tmp" == "Former revisions:" ]]
110          then
111             line_stop=$line_count
112          fi
113
114#
115#--       check if starting point is reached
116          if [[ $line_start -eq 9999999 && "$line_tmp" == "Current revisions" ]]
117          then
118             (( line_start = line_count + 2 ))
119             comment_char=${line:0:1}
120          fi
121
122#
123#--       read comment line
124          if [[ $line_count -ge $line_start && $line_stop -eq 0 ]]
125          then
126
127#
128#--          check for empty comments
129             if [[ $line_count -eq $line_start && "${line:2:10}" != "" && "${line:2:10}" != " " ]]
130             then
131                printf "\n  *** Revisions found in $filename\n"
132                found_comment=true
133                cp $filename $filename~
134             fi
135
136#
137#--          when comments are found, save comment lines to $comments
138             if [[ "$found_comment" == true ]]
139             then
140                comments="$comments\n$line"
141                list_delete="$list_delete;${line_count}d"
142             fi
143          fi
144
145#
146#--       get the timestamp from the current revision
147          if [[ "$comments" != "" && $line_count -eq $line_stop+2 ]]
148          then
149            timestamp=`echo $line | cut -d" " -s -f4-7`
150            comments="$comment_char $timestamp$comments"
151          fi
152
153       done <"$filename"
154
155#
156#--    move comments from current revisions to former revisions
157       if [[ "$found_comment" == true ]]
158       then
159
160          (( count_changes = count_changes + 1 ))
161
162#
163#--       insert comments to Former Revisions
164          (( line_stop = line_stop + 4 ))
165          sed -i "${line_stop}i$comments" $filename
166
167#
168#--       delete comments from current revisions and insert two blank lines
169          list_delete=${list_delete#?}
170          sed -i "$list_delete" $filename
171          sed -i "${line_start}i${comment_char} " $filename
172          sed -i "${line_start}i${comment_char} " $filename
173
174       fi
175
176    done
177
178#
179#-- inform the user about the changes
180    if  [[ $count_changes -gt 0 ]]
181    then
182       printf "\n  *** $count_files documents checked.\n"
183       printf "  *** $count_changes changed documents found.\n"
184       printf "  *** You can now perform svn commit -m 'last commit documented' trunk\n"
185       printf "\n  +++ THIS IS AN ALPHA VERSION. PLEASE CHECK THE MODIFIED FILES BEFORE COMMITTING\n"
186    else
187       printf "\n  *** $count_files documents checked.\n"
188       printf "  *** No documented modifications found.\n"
189    fi
Note: See TracBrowser for help on using the repository browser.