As time permits, we're going to try to show off some of C-Kermit 7.0's
new features in a series of case studies posted here. If you'd like
to post your own stories, feel free -- that's what this newsgroup is
for! Ditto if you'd like to suggest a topic to be presented.

Today's case study shows how C-Kermit 7.0 can be used to clean up after
itself. As those of you who have been following our neverending saga
know, the C-Kermit 7.0 release was preceded by a long series of Alpha
and Beta tests, in each of which we tried to make binaries available for
as many platforms as possible. For example, the Solaris 2.5.1 Intel
test binary names look like:

Within a few days after release, we had about 170 final binaries (keep
'em coming!), and hundreds more test ones, each binary consuming about
a megabyte of disk space. Before long, our server disk was running out
of space.

Problem: Given about 600 C-Kermit binaries, how to remove test binaries
for builds that have a final release, but preserve test binaries for
the other platforms that we don't yet have final builds for?

Here's how to do it with a Kermit script (the lines are tagged by numbers
that are not part of the script):

This line is used in UNIX to make the script directly executable
from the shell prompt, just like a shell script. For details,
see
Section 7.19 of the update notes.

We set our current directory to the Kermit binaries directory.

The SPACE command tells how much disk space is used and free.

This line shows a bunch of new stuff. ".\%n := " is a new
way of assigning values to variables, explained in
Section 7.9 of the update notes.
It means the same as "assign \%n ". There are
several other forms too, each for a different purpose. The value
in this case is whatever is returned by the call to the built-in
function \ffiles(), namely the number of files that matches the
given pattern. This function has been with us for years, but
there are two new things to notice in the argument list. First,
the pattern supports [xy] notation for characters in a set, and
second, the new second argument specifies an array to be loaded
with the names of all matching files, in this case all the
C-Kermit 7.0 final release binaries ("ck" followed by any single
character ('?') followed by "196" followed by either a hyphen "-"
or a period ".", followed by other stuff "*").

Now we loop through the \%n filenames in the \&a[] array.

For ease of notation, we assign the current array element to \%f.

Print the current filename.

Now we construct a pattern to match all test versions of the same
build. We do this by replacing the '6' of "196" in the original
filename by a pattern that matches '3', '4', '5', or '6' followed
by 'a' (for Alpha) or 'b' (Beta), followed by two digits. For
complete details on Kermit's new pattern-matching syntax, see
Section 4.9 of the update notes.

We set the variable \%m equal to the number of files that matches
this pattern, i.e. the number of test binaries we can delete for
this build.

If \%m is greater than 0 we have some test binaries to delete.
Note the enclosing parentheses; these are optional (in this case)
but in more complicated situations they can be used for grouping
and precedence, e.g. in compound Boolean expressions used as IF
and WHILE conditions. Also note the use of IF rather than XIF --
the distinction is no longer necessary. See
Section 7.20 about
new IF syntax and Boolean expressions.

We print the pattern and the number of matches.

And we loop through the files whose names matched the pattern.

This statement was used instead of DELETE while debugging but then
was commented out for the real run (you can also use DELETE /SIMULATE
for this purpose).

We delete the old test binary "verbosely", i.e. with a message.
Lines 15-17 are the closing brackets on the various loops and if's.

Then we find out how much space we freed (a lot!), and an EXIT command
is included at the end; otherwise Kermit issues its prompt
and waits for more commands. Kerbang scripts are typically
terminated by EXIT.

Note that the arrays created by the \ffiles() function did not need to
be declared; they were created dynamically. The array-loading functions
are explained in
Sections 4.11.4 and
7.10 of the update notes.

We run this script simply by typing its name. No need to start Kermit
first; in fact, we never even *see* Kermit.

This is a rather simple script. In fact it could have done more; for
example, removing ALL extraneous files, such as older test binaries for
which newer test binaries exist, but not a final release binary. Tasks
like this are illustrated in some of the file management scripts in the
C-Kermit script
library.