home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / fish / 771-780 / ff773 / rexxprogs / sz.rexx < prev    next >
OS/2 REXX Batch file  |  1992-12-05  |  3KB  |  149 lines

  1. /* Sz.rexx - a formatted, alphabetized dir + filesize display utility.   */
  2. /* Works best on a 68030, because its not real fast on a standard 68000. */
  3.  
  4. /* REQUIRES QuickSort, & the arp, rexxsupport, and rexarplib libraries.  */
  5. /* Supports wildcards (*, ?, or #?) */
  6.  
  7. /*      copyright 1990 Richard Lee Stockton and Gramma Software.         */
  8. /*    This code is FREELY DISTRIBUTABLE as long as this copyright        */
  9. /*   notice remains, unchanged, at the start of the code. Thank you.     */
  10.  
  11.  
  12. /* Mount needed libraries if I can find 'em */
  13.  
  14. IF(~EXISTS("libs:rexxsupport.library")|~EXISTS("libs:rexxarplib.library")) THEN
  15.  DO
  16.     SAY "Couldn't find needed library (rexxsupport and/or rexxarplib)."
  17.     EXIT 20
  18.  END
  19. CALL ADDLIB('rexxsupport.library',0,-30,0)
  20. CALL ADDLIB('rexxarplib.library',0,-30,0)
  21.  
  22.  
  23. /* Mount the QuickSort function if it's not up.  (Thanks Marvin!) */
  24.  
  25. IF ~SHOWLIST('P','QuickSortPort') THEN
  26.   DO
  27.     ADDRESS COMMAND "run quicksort >NIL:"
  28.     DO i=1 TO 10
  29.       IF ~SHOWLIST('P','QuickSortPort') THEN CALL DELAY(20)
  30.       ELSE LEAVE i
  31.     END
  32.     IF ~SHOWLIST('P','QuickSortPort') THEN
  33.       DO
  34.         SAY "Unable to find QuickSortPort."
  35.         EXIT 20
  36.       END
  37.   END
  38. CALL ADDLIB('QuickSortPort',-30)
  39.  
  40.  
  41. /* get (or make) the file specification */
  42.  
  43. PARSE ARG spec .
  44. IF spec="" THEN spec=PRAGMA("D")
  45. IF POS("*",spec)=0 & POS("?",spec)=0 THEN
  46.   DO
  47.     test=RIGHT(spec,1)
  48.     IF test=":" | test="/" THEN spec=spec"*"
  49.     ELSE spec=spec"/*"
  50.   END
  51.  
  52.  
  53. /* fetch the filelist */
  54.  
  55. files.=""
  56. IF FileList(spec,files,,E)=0 THEN
  57.   DO
  58.     SAY "A directory of" spec "does not produce any names."
  59.     EXIT 10
  60.   END
  61.  
  62.  
  63. /* get the fileinfo, fill in the stem parts, and keep running totals. */
  64. /* I count the total FILE bytes including file headers, but ignoring  */
  65. /* drawer headers so I know how much disk-space the FILES will take.  */
  66. /*   This is the part that gets rather slow on large directories..    */
  67.  
  68. longest=0
  69. bytes=0
  70. dirs=0
  71. size.=""
  72. DO i=1 TO files.0
  73.   info=STATEF(files.i)
  74.   indx=LASTPOS("/",files.i)
  75.   IF indx=0 THEN indx=LASTPOS(":",files.i)
  76.   files.i=SUBSTR(files.i,indx+1)
  77.   temp=files.i
  78.   size.temp=word(info,2)
  79.   test=LENGTH(files.i)
  80.   IF WORD(info,1)="FILE" THEN
  81.     DO
  82.       test=test+1+LENGTH(size.temp)
  83.       bytes=bytes+size.temp+512      /* 512=one block for fileheader */
  84.     END
  85.   ELSE
  86.     DO
  87.       size.temp=-1   /* allow for zero length files by making dir=-1 */
  88.       dirs=dirs+1
  89.     END
  90.   IF test>longest THEN longest=test
  91. END
  92.  
  93.  
  94. /* sort it */
  95.  
  96. call QSORT(1,files.0,files)
  97.  
  98.  
  99. columns=77%(longest+1)
  100.  
  101.  
  102. /* window pen color codes */
  103.  
  104. def  = ""
  105. pen1 = ""
  106. pen2 = ""
  107. pen3 = ""
  108. bak1 = ""
  109. bak2 = ""
  110. bak3 = ""
  111.  
  112.  
  113. /* seperate the files from the dirs */
  114.  
  115. DO i=1 TO files.0
  116.   temp=files.i
  117.   IF size.temp>=0 THEN
  118.      files.i=files.i RIGHT(size.temp,longest-length(files.i)-1)
  119.   ELSE files.i=pen3||LEFT(files.i,longest)||def
  120. END
  121.  
  122.  
  123. /* format the drawer string */
  124.  
  125. string=bak2 spec "="
  126. IF files.0>dirs THEN
  127.   DO
  128.     string=string bytes "bytes in" files.0-dirs "files"
  129.     IF dirs>0 THEN string=string "+"
  130.   END
  131. IF dirs>0 THEN string=string dirs "drawers"
  132. SAY string def
  133.  
  134.  
  135. /* format the lines */
  136.  
  137. lines=files.0%columns
  138. IF files.0//columns>0 THEN lines=lines+1
  139. DO i = 1 TO lines;
  140.   string=pen2"|"def||files.i||pen2"|"def
  141.   DO ii=1 TO columns-1
  142.     j=i+ii*lines
  143.     IF files.j~="" THEN string=string||files.j||pen2"|"def
  144.   END
  145.   SAY string
  146. END
  147.  
  148. /* end of Sz.rexx  |  16 October 1990 */
  149.