home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / disk / directory / dopuslharexx / arexx / listlha.rexx < prev    next >
OS/2 REXX Batch file  |  1995-02-27  |  6KB  |  275 lines

  1. /*rx
  2.  *
  3.  * ListLhA.rexx - List and display an LhA archive file in a DOpus window
  4.  *                (companion script ExtractLhaFiles.rexx will allow the user 
  5.  *                to select and extract files to the destination window)
  6.  *
  7.  * $VER: ListLhA 40.5 (03/01/94) by Geoff Seeley
  8.  *
  9.  * Usage: ARexx command ListLhA.rexx (from DOpus)
  10.  *
  11.  */
  12.  
  13. /* configuration variables (change these to suit your setup) */
  14.  
  15. LhaCommand = 'XFH_Work:C/Archivers/File/LhA -x -m v '
  16. LhaOutput  = 'T:lha_out'
  17.  
  18. /*--------------------------------------------------------------------------*/
  19.  
  20. /* misc. variables */
  21.  
  22. DOpusPort  = 'DOPUS.1'
  23.  
  24. LhaHeader  = '--------'
  25.  
  26. userdata     = '  0'      /* default      */
  27. fgpen        = '  1'      /* palette 1    */
  28. bgpen        = '  0'      /* palette 2    */
  29. selectable   = ' 1'       /* can select   */
  30. unselectable = ' 0'       /* can't select */
  31. show         = ' 1'       /* update win   */
  32. before       = ' -1'      /* add to end   */
  33.  
  34. /* make sure we've got somebody to talk to... */
  35.  
  36. if showlist('Ports', DOpusPort) = 0 then do
  37.    say 'Directory Opus Arexx port not found. Aborting.'
  38.    call CleanUp
  39. end
  40. else do
  41.  
  42.    /* make sure DOpus is listening to us... */
  43.  
  44.    address 'DOPUS.1'
  45.    options results
  46.  
  47.    /* get some information from DOpus */
  48.  
  49.    Status 3
  50.    CurrentWindow = Result
  51.  
  52.    /* check if window is already and LhA archive */
  53.  
  54.    Status 14 CurrentWindow
  55.    LhaFileName = Result
  56.  
  57.    /* if we don't see the proper extension, look at file in window */
  58.  
  59.    if (IsLhAFile(LhaFileName) = 0) then do
  60.  
  61.       /* get name of LhA archive file selected */
  62.  
  63.       GetNextSelected CurrentWindow
  64.       LhaFileName = result
  65.  
  66.       /* make sure its got the right extension */
  67.  
  68.       if (IsLhAFile(LhaFileName) = 0) then do
  69.  
  70.          Notify "Sorry, You *must* select an archive file\ending with '.LHA' or '.LZH'\Aborting."
  71.          TopText "List LhA archive aborted."
  72.          call CleanUp
  73.  
  74.       end
  75.  
  76.       /* get the directory of the LhA archive */
  77.  
  78.       Status 13 CurrentWindow
  79.       LhaFilePath = result
  80.  
  81.       /* make a full path/filename from above */
  82.  
  83.       LhaArchive = LhaFilePath || LhaFileName
  84.  
  85.    end
  86.    else do
  87.  
  88.       /* get path to archive, check if it exists */
  89.  
  90.       call FindLhAPath
  91.       LhaArchive = LhaFilePath || LhaFileName
  92.  
  93.       if ~exists(LhaArchive) then do
  94.          Notify "Can't find LhA archive " || LhaArchive
  95.          call CleanUp
  96.       end
  97.    end
  98. end
  99.  
  100. /* setup DOpus window and tell user what's happening */
  101.  
  102. ClearWin CurrentWindow
  103. SetWinTitle LhaFileName
  104.  
  105. Busy on
  106.  
  107. TopText "Getting list of files from archive..."
  108.  
  109. /* make a listing file from the archive so we can parse it... */
  110.  
  111. CliString = LhaCommand || LhaArchive || ' > ' || LhaOutput
  112. address command CliString
  113.  
  114. /* parse the list of LhA files */
  115.  
  116. call ParseLhaList
  117.  
  118. /* That's all folks... */
  119.  
  120. TopText "Finished. Select desired file(s) and extract using ExtLhaFiles button."
  121.  
  122. Busy off
  123.  
  124. call CleanUp
  125.  
  126. exit
  127.  
  128. /*---------------------------------------------------------------------------*/
  129.  
  130. ParseLhaList: /* open the listing file, and parse it */
  131.  
  132.    if open(LhaList, LhaOutput, 'R') then do
  133.  
  134.       /* skip the header */
  135.  
  136.       junk = ''
  137.  
  138.       do while left(junk, 8, '') ~= LhaHeader & ~eof(LhaList)
  139.          junk = readln(LhaList)
  140.       end
  141.  
  142.       if eof(LhaList) then do
  143.  
  144.          /* what the hell?? Abort. */
  145.  
  146.          Notify "No files found in selected LhA archive\Aborting."
  147.          call CleanUp
  148.  
  149.       end
  150.  
  151.       /* read in list of files */
  152.  
  153.       FileNumber = 1
  154.       line = ''
  155.       do while line ~= LhaHeader & ~eof(LhaList)
  156.  
  157.          line = readln(LhaList)
  158.  
  159.          /* is it a comment? junk these */
  160.  
  161.          if left(line, 1) = ':' then
  162.             iterate
  163.  
  164.          /* we're outta here... */
  165.  
  166.          if left(line, 8, '') = LhaHeader then
  167.             leave
  168.  
  169.          TopText 'Listing LhA archive. Please Wait. Parsing Entry #' || FileNumber
  170.          FileNumber = FileNumber + 1
  171.  
  172.          /* extract filename/path */
  173.  
  174.          FSize = substr(line, 1, 8)
  175.          FName = substr(line, 44)
  176.  
  177.          File = FSize||' '||FName
  178.          
  179.          /* DOpus only wants 256 chars... */
  180.  
  181.          if length(File) > 255 then
  182.  
  183.             File = left(File, 255)
  184.  
  185.          /* need to en-case the string in quotes so ARexx passes it through unmolested... */
  186.  
  187.          File = '"'||File||'"'
  188.  
  189.          /* add file entry to DOpus window */
  190.  
  191.          Entry = File || userdata || fgpen || bgpen || selectable || show || before 
  192.          AddCustEntry Entry
  193.  
  194.       end
  195.  
  196.       /* grab totals */
  197.  
  198.       TotalsLine = readln(LhaList)
  199.  
  200.       close(LhaList)
  201.  
  202.       /* add two unselectable entries for the totals */
  203.  
  204.       File = '"'||LhaHeader||'"'
  205.       Entry = File || userdata || fgpen || bgpen || unselectable || show || before 
  206.       AddCustEntry Entry
  207.  
  208.       FSize = substr(TotalsLine, 1, 8)
  209.       FName = substr(TotalsLine, 44)
  210.       File = '"'||FSize||' '||FName||'"'
  211.       Entry = File || userdata || fgpen || bgpen || unselectable || show || before 
  212.       AddCustEntry Entry
  213.  
  214.       /* add invisible entry giving us the path */
  215.  
  216.       File = '"'||LhaFilePath||'"'
  217.       Entry = File || userdata || bgpen || bgpen || unselectable || show || before 
  218.       AddCustEntry Entry
  219.  
  220.    end
  221.    else do
  222.  
  223.       TopText "Can't open temp file " || LhaOutput
  224.       call CleanUp
  225.  
  226.    end
  227.  
  228. return
  229.  
  230. /*--------------------------------------------------------------------------*/
  231.  
  232. IsLhAFile: procedure   /* look at extension, return 1 if right, else 0 */
  233.  
  234.    parse arg AFileName
  235.  
  236.    lps = lastpos(".", AFileName)               
  237.    if lps = 0 then                           
  238.       return 0
  239.  
  240.    FileExt = upper(right(AFileName,length(AFileName)-lps))
  241.  
  242.    if FileExt ~= "LHA" & FileExt ~= "LZH" then
  243.       return 0
  244.    else
  245.       return 1
  246.  
  247. return 0
  248.  
  249. /*--------------------------------------------------------------------------*/
  250.  
  251. FindLhAPath: /* grab invisible file path to archive */
  252.  
  253.    /* find number of entries, path is the last one */
  254.  
  255.    'Status 6 -1'
  256.  
  257.    GetEntry Result
  258.    LhaFilePath = Result
  259.  
  260. return
  261.  
  262. /*--------------------------------------------------------------------------*/
  263.  
  264. CleanUp: /* Remove any files and exit */
  265.  
  266.    if exists(LhaOutput) then
  267.       delete(LhaOutput)
  268.  
  269.    Busy off
  270.  
  271.    exit
  272.  
  273. return
  274.  
  275.