source: palm/trunk/SCRIPTS/document_changes @ 1433

Last change on this file since 1433 was 1328, checked in by maronga, 11 years ago

last commit documented

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