source: palm/trunk/SCRIPTS/document_changes @ 1807

Last change on this file since 1807 was 1805, checked in by maronga, 9 years ago

last commit documented

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