From: TENAGLIA@mis.mcw.edu (Chris Tenaglia - 257-8765)
Newsgroups: comp.lang.icon
Subject: Nice Sample VMS Program
Date: 5 Sep 92 14:31:47 GMT
Distribution: inet
Organization: Medical College of Wisconsin (Milwaukee, WI)


We'll there probably aren't a not of X-icon users out there yet. There are
probably not a lot of VMS-icon users either, but VMS users usually seem to
need a little more help (I know I did when I first started). Here's a
little program that does DIR/SIZE sorting by size and filterable by boolean
on the size rather than regular expression on the file. I call the program
SIZES. Here are some samples :

                  ICONX SIZES EQ 0    ! find files with 0 blocks
                  ICONX SIZES GT 1000 ! find files over 1000 blocks in size
                  ICONX SIZES NE 8    ! find files that aren't 8 blocks
                  ICONX SIZES         ! display all files

Output files are specified using unixlike redirectors:

     ICONX SIZES LT 100 >S.TMP      ! write output to S.TMP
     ICONX SIZES GT 2000 >>S.TALLY  ! append output to S.TALLY

The output is sorted by size from highest to lowest. The program uses
string scanning and has comments. Maybe someone might want to post a
unix or DOS version? Here's the code :

#
# FILE : SIZES.ICN
# DESC : VMS DIR/SIZE SORTED BY SIZE INSTEAD BY FILENAME
# USE  : ICONX SIZES [compare size]
#        WHERE compare IS AL, GT, LT, EQ, GE, LE, NE AND
#        SIZE IS A NUMBER MEANING ALLOCATED BLOCKS SO FOR
#        EXAMPLE iconx sizes gt 1000 WILL DO A DIR/SIZE
#        SHOWING ONLY FILES GREATER THAN 1000 BLOCKS SORTED
#        BY BLOCKS WITH BIGGEST FILES FIRST.
#
# UPDATE          BY          WHAT
# 5-SEP-1992      TENAGLIA    INITIAL CREATION
#
procedure main(param)
  cache   := []
  dir     := ""
  grand   := 0
  if *param = 2 then       # if something is specified
    {                      # then
    method := param[1]     # get method of compare
    limit  := param[2]     # compare sizes with this
    } else {               # otherwise
    method := "al"         # look at all of them
    limit  := -1           # and this is a place holder
    }
  command := "dir/size=alloc/nohead/notrail "
  pipe    := open(command,"pr")
  while (name := read(pipe)) & (size := read(pipe)) do
    {
    if dir == "" then name ? (dir := tab(upto(']') + 1))
    name ? {
           move(upto(']'))
           file := tab(0)
           }
    if compare(size,limit,param[1]) then
      {
      put(cache,right(size,7) || "   " || trim(file))
      grand +:= size
      }
    }
  close(pipe)
  results := sort(cache)
  write("\n",dir,"\n")
  while write(pull(results))
  write("\nTotal Allocated Blocks = ",grand)
  end

#
# GENERIC BOOLEAN COMPARE EITHER RETURNS OR FAILS
# A & B MUST BE NUMERICS, AND CONDITION IS A BOOLEAN ABBREVIATION
#
procedure compare(a,b,condition)
  case condition of
    {
    "al" : return                  # always
    "gt" : if a >  b then return   # greater than
    "lt" : if a <  b then return   # less than
    "eq" : if a =  b then return   # equal to
    "ge" : if a >= b then return   # greater than or equal to
    "le" : if a <= b then return   # less than or equal to
    "ne" : if a ~= b then return   # not equal
    default : fail                 # never
    }
  fail
  end

################# end of program ####################

Chris Tenaglia (System Manager) | Medical College of Wisconsin
8701 W. Watertown Plank Rd.     | Milwaukee, WI 53226
(414)257-8765                   | tenaglia@mis.mcw.edu, mcwmis!tenaglia