/* A du-like utility in REXX Reports the disk space used in a directory */ call rxfuncadd 'SysLoadFuncs','RexxUtil','SysLoadFuncs' call SysLoadFuncs RootDir=Directory() rc=ProcessDir(RootDir) Exit ProcessDir: Procedure Expose RootDir Parse Arg Dir rc=SysFileTree("*","Dirs.","DO") Arrays="Size. SubDir." NMax=-1 NDirs=Dirs.0+1 Dirs.NDirs=RootDir Size.0=NDirs Do i=1 to NDirs Size=DirSize(Dirs.i) Parse Var Dirs.i (RootDir) SubDir.i . If SubDir.i="" then SubDir.i="\" n=Length(SubDir.i) If N>NMax then NMax=N Size.i=Right(Size,11) end /* do */ NMax=NMax+1 Call HeapSort Total=0 Do i=1 to NDirs Say Left(SubDir.i,NMax) Size.i Format(Size.i/1024,8,1)||"K" Format(Size.i/1048576,5,1)||"M" Total=Total+Size.i end /* do */ Say Copies("-",NMax+34) Say Copies(" ",NMax) Right(Total,11) Format(Total/1024,8,1)||"K" Format(Total/1048576,5,1)||"M" Return 1 DirSize: Procedure Expose RootDir Parse Arg Dir rc=Directory(Dir) If Dir=RootDir then rc=SysFileTree("*","Files.","F") else rc=SysFileTree("*","Files.","FS") Sum=0 Do i=1 to Files.0 Parse Var Files.i Date Time Size . Sum=Sum+Size end /* do */ Return Sum /* ------------------------------------------------------------------ */ /* function: heap sort routine that tracks multiple stems */ /* */ /* call: HeapSort */ /* */ /* returns: nothing */ /* */ /* notes: The variable Arrays must be a string containing the names*/ /* of the stems that will be sorted. The first stem listed */ /* is the one that is used as the key (i.e., the values that*/ /* will be sorted) and the others are the ones whose values */ /* follow the items in the key array. For example, suppose */ /* you have a stem called Names., another array Weights., */ /* and another array Heights. and you want to sort the */ /* arrays by the weights. You would call HeapSort with the */ /* Arrays variable set as Arrays="Weights. Names. Heights." */ /* (The order of the secondary stems Names. and Heights. is */ /* not important.) */ /* */ /* reference: Sedgewick, "Algorithms" */ /* */ Heapsort: PROCEDURE expose (Arrays) start=Time("R") NArrays=Words(Arrays) Interpret "NItems="||Word(Arrays,1)||"0" /* Copy the original stems to temporary ones */ Do i=0 to NItems Interpret "Stem.i="||Word(Arrays,1)||i Do j=2 to NArrays Interpret "Stem.i.j="||Word(Arrays,j)||i end /* do */ end /* do */ M = stem.0 N = M do k=M % 2 to 1 by -1 call DownHeap k N end /* do */ do while N>1 t = stem.1 Do i=2 to NArrays t.i=Stem.1.i end /* do */ stem.1 = stem.n Do i=2 to NArrays Stem.1.i=Stem.n.i end /* do */ stem.n = t Do i=2 to NArrays Stem.n.i=t.i end /* do */ n = n-1 call DownHeap 1 N end /* do */ /* Re-order the original stems */ Do i=0 to NItems Interpret Word(Arrays,1)||i||"="||"Stem.i" Do j=2 to NArrays Interpret Word(Arrays,j)||i||"="||"Stem.i.j" end /* do */ end /* do */ /* Stop the timer */ end=time("R") elapsed=end-start RETURN elapsed /* subroutine of HeapSort */ DownHeap: PROCEDURE expose stem. NArrays parse Arg k N v = stem.k Do i=2 to NArrays v.i=Stem.k.i end /* do */ do while k <= N%2 j = k+k if j < n then do i = j+1 if stem.j < stem.i then j=j+1 end /* do */ if v >= stem.j then signal label stem.k = stem.j Do i=2 to NArrays Stem.k.i=Stem.j.i end /* do */ k = j end /* do */ Label: stem.k = v Do i=2 to NArrays Stem.k.i=v.i end /* do */ RETURN