home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / opus / v4 / dopuslharexx / arexx / selectfileslha.rexx < prev   
OS/2 REXX Batch file  |  1995-09-18  |  3KB  |  176 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.3 (03/01/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.  
  28. /* make sure we've got somebody to talk to */
  29.  
  30. if showlist('Ports', DOpusPort) = 0 then do
  31.    say 'Directory Opus ARexx port not found. Aborting.'
  32.    call CleanUp
  33. end
  34.  
  35. address 'DOPUS.1'
  36. options results
  37.  
  38. /* get window information from DOpus */
  39.  
  40. Status 3
  41. CurrentWindow = result
  42.  
  43. /* get the path/name of the LhA archive file */
  44.  
  45. Status 14 CurrentWindow
  46. LhaArchive = result
  47.  
  48. /* make sure it's an LhA archive listing buffer */
  49.  
  50. if right(LhaArchive, 4, ' ') ~= LhaExt1 & right(LhaArchive, 4, ' ') ~= LhaExt2 then do
  51.  
  52.    Notify "Sorry, buffer isn't an LhA archive.\You must use the ListLha button first."
  53.    call CleanUp
  54.  
  55. end
  56.  
  57. TopText "Selecting Files in an LhA Archive Matching Sub-String"
  58.  
  59. Busy on
  60.  
  61. /* ask user for a search pattern */
  62.  
  63. Status 26
  64. OldOkay = result
  65.  
  66. Status 27
  67. OldCancel = result
  68.  
  69. Status 26 set 'Select'
  70. Status 27 set 'Cancel'
  71.  
  72. MsgString = '"Please enter a sub-string to match on:"'
  73. GetString MsgString
  74.  
  75. DoSelect = RC
  76. Pattern = Result
  77.  
  78. /* reset previous values */
  79.  
  80. Status 26 set OldOkay
  81. Status 27 set OldCancel
  82.  
  83. if DoSelect = "0" then do
  84.  
  85.    /* select the files */
  86.  
  87.    call ValidatePattern
  88.    call SelectFiles
  89.  
  90.    /* list totals */
  91.  
  92.    address command GetSizesLhARexx
  93.  
  94. end
  95. else do
  96.  
  97.    TopText "File Selection Aborted..."
  98.    call CleanUp
  99.  
  100. end
  101.  
  102. call CleanUp
  103.  
  104. exit
  105.  
  106. /*--------------------------------------------------------------------------*/
  107.  
  108. SelectFiles: /* select files based on pattern */
  109.  
  110.    Index = 1
  111.    Entry = ""
  112.    Pattern = upper(Pattern)
  113.  
  114.    do while Entry ~= LhaHeader
  115.  
  116.       GetEntry Index
  117.       Entry = result
  118.  
  119.       if Entry ~= LhaHeader then do
  120.  
  121.          TopText "Checking Entry #" || Index
  122.          ScrollToShow Index
  123.  
  124.          /* grab file name/path, protect in quotes */
  125.                                             
  126.          File = substr(Entry, 10)
  127.  
  128.          if SelectAll = 1 then
  129.             StrIdx = 1
  130.          else
  131.             StrIdx = index(upper(File), Pattern)
  132.  
  133.          if StrIdx > 0 then do
  134.             selection = Index - 1 ||' '|| 1 ||' '|| 1
  135.             SelectEntry selection
  136.          end
  137.  
  138.          Index = Index + 1
  139.       end
  140.    end
  141.  
  142. return
  143.  
  144. /*--------------------------------------------------------------------------*/
  145.  
  146. ValidatePattern: /* make sure pattern is ok */
  147.  
  148.    /* special cases */
  149.  
  150.    if Pattern = "*" then do
  151.  
  152.       SelectAll = 1
  153.       return
  154.    end
  155.  
  156.    /* remove leading/trailing spaces */
  157.  
  158.    Pattern = strip(Pattern)
  159.  
  160.    /* remove wildcards (for now) */
  161.  
  162.    Pattern = compress(Pattern, '*?#')
  163.  
  164. return
  165.  
  166. /*--------------------------------------------------------------------------*/
  167.  
  168. CleanUp: /* clean up files and exit */
  169.  
  170.    Busy off
  171.  
  172.    exit
  173.  
  174. return
  175.  
  176.