Cover V03, I05
Article
Listing 1

sep94.tar


Listing 1: The vedit script

1   :
2   #
3   # vedit - VI version editing
4   # Copyright Unilabs Research Group, 1994
5   #
6   # This program implements file version numbering like that which is
7   # used on DEC VAX systems.
8   #
9   # Check to insure that we have at least one option, and print an error
10   # if we don't
11   #
12   if [ $# -lt 1 ]
13   then
14      echo "Usage:  `basename $0` file [file ...]"
15      exit 1
16   fi
17   #
18   # loop for each file in the argument list
19   #
20   for file in $*
21   do
22      #
23      # Determine if the file is under "version" control
24      # list the files which start with the name in the argument list and pipe
25      # that list into grep, looking for files under VersionVI control.  Pipe
26      # that list into sed substituting spaces for alphabetic and numerical
27      # characters followed by a semi-colon.  Pipe that list into sort doing a
28      # reverse numerical sort, and reading the first line.
29      #
30      verList=`ls $file* | grep "$file;" |
31                sed 's/.*;//g' | sort -rn | head -1`
32      #
33      # If there is a version in this variable, then it is the highest version
34      # number in the file list.
35      #
36      if [ "$verList" ]
37      then
38         #
39         # increment the version number
40         #
41         version=`expr $verList + 1`
42         original="$file;$verList"
43         newfile="$file;$version"
44      else
45         #
46         # This is a new file - start the version at 1
47         #
48         version=1
49         original="$file"
50         newfile="$file;$version"
51         #
52         # Check to see if the file REALLY EXISTS
53         #
54         if [ ! -f ${original} ]
55         then
56            touch ${original}
57         fi
58      fi
59      #
60      # We have to copy the last edit file to the new version so we have
61      # something to edit.
62      #
63      error=`cp ${original} ${newfile} 2>&1`
64      #
65      # OOPS - there was an error
66      #
67      if [ $? -ne 0 ]
68      then
69         error=`echo $error | sed 's/.*: //g' 2>&1`
70         echo "Your edit of ${newfile} is aborted."
71         echo "Attempting to access ${original} has reported the follwing \c"
72         echo "system error\n\n\t$error\n"
73         echo "Aborting edit."
74         exit 2
75      fi
76      echo "Loading ${newfile} for edit ..."
77      # Load vi and edit
78      #
79      vi ${newfile}
80      if [ $version -gt 1 ]
81      then
82         #
83         # See of the user actually made changes
84         #
85         diff ${original} ${newfile} 2>&1 >/dev/null
86         EDIT=$?
87      else
88         #
89         # This is the first edit - so don't run diff, and record the
90         # edit history
91         #
92         if [ -r ${newfile} ]
93         then
94            EDIT=1
95         fi
96      fi
97      #
98      # the user DID make changes
99      if [ EDIT -eq 1 ]
100      then
101         #
102         # Count the number of lines and bytes in the file
103         #
104         set `wc ${newfile}`
105         lines=`echo $1 | sed 's/ //g'`
106         bytes=`echo $3 | sed 's/ //g'`
107         #
108         # record the edit history for this file
109         #
110         echo "${newfile}\t`logname`\tlines=${lines}\tbytes=${bytes}\
111         `date`" >> $file.INDEX
112         #
113         # Now link the newly edited version to the basename - that is the file
114         # name without using the version number
115         #
116         ln $newfile $file
117      else
118         #
119         # remove the higher version copy as the user made NO changes
120         #
121         echo "${newfile} was not edited.  Restoring to ${original}"
122         rm ${newfile}
123      fi
124   done