home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / direa.zip / DIREA.CMD
OS/2 REXX Batch file  |  1994-02-05  |  4KB  |  182 lines

  1. /* DirEA.cmd
  2.  * List a directory, showing any .SUBJECT and .COMMENTS EAs for each file.
  3.  *
  4.  * Copyright 1994 by William F. Schindler. Permission is granted for free
  5.  * use and distribution.
  6.  *
  7.  * Author:  Bill Schindler
  8.  * Created: 12-Jan-1994
  9.  *
  10.  * --------------------------------- History ---------------------------------
  11.  * 05-Feb-1994    wfs  Check for directory in file spec argument
  12.  *             Add option for showing .COMMENTS EA
  13.  *             Add usage subroutine
  14.  * ---------------------------------------------------------------------------
  15.  */
  16.  
  17. CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  18. CALL SysLoadFuncs
  19.  
  20. /*
  21.  * Process any command line arguments
  22.  */
  23. PARSE ARG filespec
  24.  
  25. i = 0
  26. doComments = 0
  27. doSubdirs = ''
  28.  
  29. DO WHILE Left(filespec, 1) = '/' | Left(filespec, 1) = '-'
  30.   sep = Left(filespec, 1)
  31.   PARSE VAR filespec (sep) pgmArg filespec
  32.   pgmArg = Translate(pgmArg)
  33.  
  34.   SELECT
  35.     WHEN pgmArg = 'C' THEN
  36.       doComments = 1
  37.     WHEN pgmArg = 'S' THEN
  38.       doSubdirs = 'S'
  39.     WHEN pgmArg = '?' | Abbrev('HELP', pgmArg, 1) THEN
  40.       DO
  41.       CALL ShowUsage
  42.       SIGNAL EndIt
  43.       END
  44.     OTHERWISE
  45.       DO
  46.       SAY
  47.       SAY "Invalid command line argument '" || sep || pgmArg || "'"
  48.       SIGNAL EndIt
  49.       END
  50.   END
  51. END
  52.  
  53. SELECT
  54.   WHEN filespec = '' THEN
  55.     filespec = '*.*'
  56.   WHEN Right(filespec, 1) = '\' THEN
  57.     filespec = filespec || '*.*'
  58.   OTHERWISE
  59.     NOP
  60. END
  61.  
  62. /*
  63.  * Read the directory
  64.  */
  65. CALL SysFileTree filespec, 'files.', 'FO' || doSubdirs
  66.  
  67. SAY 'Total of' files.0 'files found for "' || filespec || '":'
  68. SAY
  69.  
  70. IF files.0 = 0 THEN
  71.   SIGNAL EndIt
  72.  
  73. /*
  74.  * Collect and parse the EAs for each file found
  75.  */
  76. longestFN = 4
  77. longestType = 4
  78. longestSubj = 7
  79.  
  80. DO i = 1 to files.0
  81.   /*
  82.    * Get .SUBJECT EA
  83.    */
  84.   longestFN = MAX(longestFN, LENGTH(FILESPEC('name', files.i)))
  85.   IF SysGetEA(files.i, '.SUBJECT', 'eaStuff') = 0 THEN DO
  86.     subjLen = '0'X
  87.     PARSE VAR eaStuff 3 subjLen 4 . 5 subject
  88.     subjLen = MIN(C2D(subjLen), 54)
  89.     subject = LEFT(subject, subjLen)
  90.     END
  91.   ELSE
  92.     subject = ''
  93.   ea.subjects.i = subject
  94.   longestSubj = MAX(longestSubj, LENGTH(subject))
  95.   /*
  96.    * Get .COMMENTS EA
  97.    */
  98.   IF doComments THEN
  99.     IF SysGetEA(files.i, '.COMMENTS', 'eaStuff') = 0 THEN DO
  100.       PARSE VAR eastuff 11 ea.comments.i
  101.       END
  102. END
  103.  
  104. /*
  105.  * Display the files and associated EAs
  106.  */
  107. SAY ' 'CENTER('File', longestFN) '|' CENTER('Subject', longestSubj)
  108. PARSE VALUE SysTextScreenSize() WITH rows cols
  109.  
  110. lastSubdir = ''
  111. extraDirs = 0
  112.  
  113. DO i = 1 to files.0
  114.   IF \ doComments THEN
  115.     CALL PageIt
  116.  
  117.   IF doSubdirs = 'S' THEN
  118.     IF lastSubdir >< FileSpec('PATH', files.i) THEN
  119.       DO
  120.       lastSubdir = FileSpec('PATH', files.i)
  121.       SAY 'Directory:  ' || FileSpec('DRIVE', files.i) || lastSubdir
  122.       extraDirs = extraDirs + 1
  123.       IF \ doComments THEN
  124.     CALL PageIt
  125.       END
  126.   /*
  127.    * Build a single line with the file name and subject
  128.    */
  129.   fn = FILESPEC('name', files.i)
  130.   IF LENGTH(fn) < longestFN THEN
  131.     fn = INSERT(' ', fn, longestFN - 1)
  132.   IF LENGTH(ea.subjects.i) < longestSubj THEN
  133.     ea.subjects.i = INSERT(' ', ea.subjects.i, longestSubj - 1)
  134.   SAY ' ' || fn '|' ea.subjects.i
  135.   /*
  136.    * If requested, show comments
  137.    */
  138.   IF doComments & ea.comments.i >< '' THEN
  139.     DO
  140.     SAY '  ' || ea.comments.i
  141.     SAY
  142.     END
  143. END
  144.  
  145. EndIt:
  146.  
  147. EXIT
  148.  
  149. /* ---------------------------------------------------------------------------
  150.  * P a g e I t
  151.  */
  152. PageIt:
  153.   /*
  154.    * Handle displaying more than one screen of data. Since we're not
  155.    * calculating the length of a .COMMENTS EA, we don't bother paging
  156.    * the output when the 'C' option is turned on.
  157.    */
  158.   IF ((i + extraDirs) // (rows - 2)) = 0 THEN DO
  159.     SAY '--- more ---'
  160.     PARSE VALUE SysCurPos() WITH row col
  161.     CALL SysCurPos row - 1, col
  162.     CALL SysGetKey 'NOECHO'
  163.     END
  164.   RETURN
  165.  
  166. /* ---------------------------------------------------------------------------
  167.  * S h o w U s a g e
  168.  */
  169. ShowUsage:
  170.   SAY
  171.   SAY "dirEA: List comments and subject EAs for one or more files"
  172.   SAY
  173.   SAY "  Usage:  dirEA [options] [pathname]"
  174.   SAY
  175.   SAY "  Options:"
  176.   SAY "    -?        Displays this usage screen"
  177.   SAY "    -C        Displays .COMMENTS EA in addition to .SUBJECT EA"
  178.   SAY "    -S        Processes pathname and its subdirectories"
  179.   SAY
  180.   SAY "  The pathname parameter defaults to '*.*'"
  181.   RETURN
  182.