home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / opus / v4 / arexx / selectfileslha.rexx < prev    next >
OS/2 REXX Batch file  |  1977-12-31  |  4KB  |  196 lines

  1. /*rx
  2.  *
  3.  * SelectFilesLhA.rexx - Allow the user to select files in an LhA buffer 
  4.  *                       window via a search pattern.
  5.  *
  6.  * $VER: SelectFilesLhA 40.4 (22/05/94) by Geoff Seeley
  7.  *
  8.  * Usage: ARexx command SelectFilesLhA.rexx (from DOpus)
  9.  *
  10.  */
  11.  
  12. /* configuration variables (change these to suit your setup) */
  13.  
  14. GetSizesLhARexx = "RX DOpus:ARexx/GetSizesLhA.rexx"
  15.  
  16. /*--------------------------------------------------------------------------*/
  17.  
  18. /* misc. variables */
  19.  
  20. DOpusPort = 'DOPUS.1'
  21.  
  22. LhaExt1    = '.lha'
  23. LhaExt2    = '.lzh'
  24. LhaHeader  = '--------'
  25.  
  26. SelectAll = 0
  27. State = 1         /* select */
  28.  
  29. if ~show(l,"rexxsupport.library") then        
  30.     call addlib("rexxsupport.library",0,-30,0)
  31.  
  32. /* make sure we've got somebody to talk to */
  33.  
  34. if showlist('Ports', DOpusPort) = 0 then do
  35.    say 'Directory Opus ARexx port not found. Aborting.'
  36.    call CleanUp
  37. end
  38.  
  39. address 'DOPUS.1'
  40. options results
  41.  
  42. /* get window information from DOpus */
  43.  
  44. Status 3
  45. CurrentWindow = result
  46.  
  47. /* get the path/name of the LhA archive file */
  48.  
  49. Status 14 CurrentWindow
  50. LhaArchive = result
  51.  
  52. /* make sure it's an LhA archive listing buffer */
  53.  
  54. if right(LhaArchive, 4, ' ') ~= LhaExt1 & right(LhaArchive, 4, ' ') ~= LhaExt2 then do
  55.  
  56.    Notify "Sorry, buffer isn't an LhA archive.\You must use the ListLha button first."
  57.    call CleanUp
  58.  
  59. end
  60.  
  61. TopText "Selecting Files in an LhA Archive Matching Sub-String"
  62.  
  63. Busy on
  64.  
  65. /* ask user for a search pattern */
  66.  
  67. Status 26
  68. OldOkay = result
  69.  
  70. Status 27
  71. OldCancel = result
  72.  
  73. Status 26 set 'Select'
  74. Status 27 set 'Cancel'
  75.  
  76. MsgString = '"Please Enter A Pattern To Match:"'
  77. GetString MsgString
  78.  
  79. DoSelect = RC
  80. Pattern = Result
  81.  
  82. /* reset previous values */
  83.  
  84. Status 26 set OldOkay
  85. Status 27 set OldCancel
  86.  
  87. if DoSelect = "0" then do
  88.  
  89.    /* select the files */
  90.  
  91.    TopText "Checking Entries. Please Wait..."
  92.  
  93.    call ValidatePattern
  94.    call SelectFiles
  95.  
  96.    /* list totals */
  97.  
  98.    GetSelectedAll                               
  99.    SelectedEntries = result                     
  100.                                              
  101.    if SelectedEntries = 'RESULT' then
  102.       TopText "No Files Currently Selected."
  103.    else
  104.       address command GetSizesLhARexx
  105.  
  106. end
  107. else do
  108.  
  109.    TopText "File Selection Aborted..."
  110.    call CleanUp
  111.  
  112. end
  113.  
  114. call CleanUp
  115.  
  116. exit
  117.  
  118. /*--------------------------------------------------------------------------*/
  119.  
  120. SelectFiles: /* select files based on pattern */
  121.  
  122.    Index = 1
  123.    Entry = ""
  124.    Pattern = upper(Pattern)
  125.  
  126.    do while Entry ~= LhaHeader
  127.  
  128.       GetEntry Index
  129.       Entry = result
  130.  
  131.       if Entry ~= LhaHeader then do
  132.  
  133.          /* grab file name/path, protect in quotes */
  134.                                             
  135.          File = upper(substr(Entry, 10))
  136.  
  137.          if SelectAll = 1 then
  138.             StrIdx = 1
  139.          else do
  140.            PatternMatch Pattern File
  141.            StrIdx = RESULT
  142.          end
  143.  
  144.          if StrIdx > 0 then do
  145.             selection = Index - 1 ||' '|| State ||' '|| 0
  146.             SelectEntry selection
  147.          end
  148.  
  149.          Index = Index + 1
  150.       end
  151.    end
  152.  
  153.    'DisplayDir -1'
  154.  
  155. return
  156.  
  157. /*--------------------------------------------------------------------------*/
  158.  
  159. ValidatePattern: /* make sure pattern is ok */
  160.  
  161.    /* special cases */
  162.  
  163.    if Pattern = "*" then do
  164.       SelectAll = 1
  165.       return
  166.    end
  167.  
  168.    if Pattern = "~" then do
  169.       SelectAll = 1
  170.       State = -1
  171.       return
  172.    end
  173.  
  174.    if Pattern = "" then do
  175.       SelectAll = 1
  176.       State = 0
  177.       return
  178.    end
  179.  
  180.    /* remove leading/trailing spaces */
  181.  
  182.    Pattern = strip(Pattern)
  183.  
  184. return
  185.  
  186. /*--------------------------------------------------------------------------*/
  187.  
  188. CleanUp: /* clean up files and exit */
  189.  
  190.    Busy off
  191.  
  192.    exit
  193.  
  194. return
  195.  
  196.