C-Kermit 7.0 Case Study #01

[ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]

Article: 10879 of comp.protocols.kermit.misc
From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
Newsgroups: comp.protocols.kermit.misc
Subject: C-Kermit 7.0 Case Study #01 - Cleaning Out Beta-Test Binaries
Date: 7 Jan 2000 23:53:58 GMT
Organization: Columbia University

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:

  cku193a03.solaris25-i386-2.5.1  (Edit 193 Alpha Test 03)
  cku195b07.solaris25-i386-2.5.1  (Edit 195 Beta  Test 07)
  cku196b11.solaris25-i386-2.5.1  (Edit 196 Beta  Test 11)
And then the final release binary for this platform is called:
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):

  1. #!/usr/local/bin/kermit +
  2. cd /pub/ftp/kermit/bin/
  3. space
  4. .\%n := \ffiles(ck?196[-.]*,&a)
  5. for \%i 1 \%n 1 {
  6.     .\%f := \&a[\%i]
  7.     echo \%f...
  8.     .\%g := \freplace(\%f,196,19[3-6][ab][0-9][0-9])
  9.     .\%m := \ffiles(\%g,&b)
 10.     if ( > \%m 0 ) {
 11.         echo { MATCHES: \%g: \%m}
 12.         for \%j 1 \%m 1 {
 13.             ; echo {   \flpad(\%j,2). \&b[\%j]}
 14.             delete /verb \&b[\%j]
 15.         }
 16.     }
 17. }
 18. space
 19. exit

Here's a line-by-line explanation:

  1. 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.

  2. We set our current directory to the Kermit binaries directory.

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

  4. 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 "*").

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

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

  7. Print the current filename.

  8. 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.

  9. 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.

  10. 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.

  11. We print the pattern and the number of matches.

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

  13. 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).

  14. 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.

- Frank

[ Top ] [ Previous] [ Next ] [ C-Kermit Home ] [ Kermit Home ]

C-Kermit 7.0 / Columbia University / kermit@columbia.edu / 7 Jan 2000