/* ARexx example for KingFisher:
 *
 * Run this program while KingFisher is active.
 *
 * Lists all programs in the database and
 * indicates on what disk their latest revision
 * can be found.
 *
 * All commands sent to KingFisher are shown in
 * UPPERCASE to more clearly indicate what is
 * going on.  KingFisher does not, of course,
 * care about case, unless, perhaps, during a
 * search operation (which we're not using here.)
 *
 * BUGS: we are checking the return code only where
 *       we expect an error condition to occur.
 *       This means that we won't handle any sort
 *       of critical errors, such as an empty data-
 *       base, or a missing disk, or other problems.
 *
 * Written by:  Udo Schuermann
 */
options results
address kingfisher1

VERSION
say "Using "result
say ""

say "The following is a list of all programs in the database,"
say "and information on the disk where their latest revisions"
say "are to be found:"
say ""

totalupdates=0
totalrevisions=0
ok = 1
MOVETO FIRST FISH
do while rc = 0
   /* save current position in the database */
   TELL FISH
   curfish = result
   TELL DISK
   curdisk = result

   /* now see if we can skip forward on the version link */
   MOVETO NEXT VERSION
   if rc = 0 then do
      totalupdates = totalupdates + 1
      /* follow all version links and count them */
      do while rc = 0
         totalrevisions = totalrevisions + 1
         MOVETO NEXT VERSION
      end
      TELL DISK
      msg = ' (Latest updated version is on disk #'||result')'

      /* return to the place from where we followed the link */
      MOVETO FISH CURFISH
   end
   else
      msg = '';

   /* now get only the title of the description */
   SHOW TITLE
   say 'Disk#'curdisk': 'result||msg
   MOVETO NEXT FISH
end

say ""
say "Statistics:"
TELL FISHCOUNT
total = result
say "Total fish in database: "total
say "Total revised fish    : "totalupdates" ("||(totalupdates*100)%total||"%)"
say "Total of all revisions: "totalrevisions" ("||(totalrevisions*100)%total||"%)"
