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

  1. /*rx
  2.  *
  3.  * LhaHandler - a Custom Handler for ListLha.rexx. Processes messages from
  4.  *              DOpus when the user double/click-m-click's on a CustEntry.
  5.  *
  6.  * $VER: LhaHandler 40.1 (23/05/94) by Geoff Seeley
  7.  *
  8.  * Usage: Run RX LhaHandler.rexx >NIL:
  9.  *        (from S:User-Startup)
  10.  *
  11.  */
  12.  
  13. /*--------------------------------------------------------------------------*/
  14. /* configuration variables (change these to suit your setup) */
  15.  
  16. LhaCommand    = 'XFH_Work:C/Archivers/File/LhA '
  17. ViewLhaFile   = 'RX DOpus:ARexx/ViewLhAFile.rexx'
  18. OutputWindow  = '>CON:30/145/640/100/LhA_Output/CLOSE/SCREENDOPUS.1 '
  19. InputWindow   = '<CON:30/245/640/50/LhA_Input/AUTO/SCREENDOPUS.1 '
  20.  
  21. /*--------------------------------------------------------------------------*/
  22. /* misc. variables */
  23.  
  24. DOpusPort   = 'DOPUS.1'
  25. LhaListPort = 'LHALIST.1'
  26.  
  27. /* need rexxsupport.library for message functions */
  28.  
  29. if ~show(l,"rexxsupport.library") then        
  30.     call addlib("rexxsupport.library",0,-30,0)
  31.  
  32. /* check if we are already running */
  33.  
  34. if showlist('Ports', LhaListPort) then do
  35.  
  36.    /* for multiple DOpus's, need to make port based on the port of the
  37.       DOpus who called us, but for now: */
  38.  
  39.    /* can't run more than one handler... */
  40.  
  41.    call ExitIt
  42.  
  43. end
  44.  
  45. options results
  46.  
  47. /* open our message port */
  48.  
  49. OurPort = openport(LhaListPort)
  50.  
  51. HandlerStatus = 'OPEN'
  52.  
  53. do until HandlerStatus = 'CLOSE'
  54.    call waitpkt(LhaListPort)
  55.    Packet = getpkt(LhaListPort)
  56.    if Packet ~= null() then do
  57.       Cmd = getarg(Packet, 0)
  58.       if Cmd = '1' | Cmd = '2' then do
  59.          Arg1 = getarg(Packet, 1) /* entry number */
  60.          Arg2 = getarg(Packet, 2) /* entry text   */
  61.          Arg3 = getarg(Packet, 3) /* userdata     */
  62.          call reply(Packet, 0)
  63.          address value DOpusPort
  64.          Busy on
  65.          if Cmd = '1' then
  66.             call HandleDoubleClick
  67.          else
  68.             call HandleClickMClick
  69.          Busy off
  70.       end
  71.       else
  72.          call reply(Packet, 0)
  73.       if Cmd = 'CLOSE' then
  74.          HandlerStatus = 'CLOSE'
  75.    end
  76. end
  77.  
  78. /* close up shop */
  79.  
  80. call closeport(OurPort)
  81.  
  82. exit
  83.  
  84. /*--------------------------------------------------------------------------*/
  85.  
  86. HandleDoubleClick: /* double click, view file */
  87.  
  88.    /* re-select this entry (double click unselects) */
  89.  
  90.    'SelectEntry '||Arg1||' 1 1'
  91.  
  92.    /* call view script */
  93.  
  94.    address COMMAND ViewLhaFile
  95.  
  96. return
  97.  
  98. /*--------------------------------------------------------------------------*/
  99.  
  100. HandleClickMClick: /* click-m-click, extract file */
  101.  
  102.    /* get env: settings */
  103.  
  104.    LhaExtractCmd = GetLhaOpts()
  105.  
  106.    /* get filename and path */
  107.  
  108.    FileName = substr(Arg2, 10)
  109.  
  110.    TopText "Extracting "||IsolateFilename(FileName)
  111.  
  112.    if ExtOpts ~= '-x x' then
  113.       FileName = IsolateFilename(FileName)
  114.  
  115.    /* get LhA archive name and path */
  116.  
  117.    OtherWindow
  118.    'Status 14 -1'
  119.    LhaArchive = result
  120.  
  121.    call FindLhAPath                  
  122.    LhaArchive = LhaPath || LhaArchive
  123.  
  124.    /* unselect the file while we're here */
  125.  
  126.    'SelectEntry '||Arg1||' 0 1'
  127.  
  128.    /* get destination directory */
  129.  
  130.    OtherWindow
  131.    'Status 13 -1'          
  132.    DestinationPath = result
  133.  
  134.    /* extract that puppy */
  135.  
  136.    CliCommand = LhaCommand || OutputWindow || InputWindow || LhaExtractCmd ||'"'|| LhaArchive||'"'
  137.    CliCommand = CliCommand || ' "'||FileName||'" "'||DestinationPath||'"'
  138.  
  139.    address command CliCommand
  140.  
  141.    'Rescan -1'
  142.  
  143.    TopText "Finished Extracting "||IsolateFilename(FileName)
  144.  
  145. return
  146.  
  147. /*--------------------------------------------------------------------------*/
  148.  
  149. FindLhAPath: /* grab invisible file path to archive */
  150.                                                       
  151.    /* find number of entries, path is the last one */ 
  152.                                                       
  153.    'Status 6 -1'                                      
  154.                                                       
  155.    GetEntry Result                                    
  156.    LhaPath = Result                                   
  157.                                                       
  158. return
  159.  
  160. /*--------------------------------------------------------------------------*/
  161.  
  162. IsolateFilename: /* given a device/path/file, return filename */
  163.  
  164.    parse arg FilePath
  165.    DivPos = max(lastpos(':', FilePath),lastpos('/', FilePath)) +1
  166.    parse var FilePath PathSpec =DivPos AFileName
  167.  
  168. return AFileName
  169.  
  170. /*--------------------------------------------------------------------------*/
  171.  
  172. GetLhaOpts: procedure expose ExtOpts OvrOpts /* get LhA options */
  173.  
  174.    if open('opts', 'ENV:LHAREXX_EXT_OPTS', 'R') then do
  175.       ExtOpts = readln('opts')
  176.       close('opts')
  177.    end
  178.    else
  179.       ExtOpts = '-x x '
  180.  
  181.    if open('opts', 'ENV:LHAREXX_OVR_OPTS', 'R') then do
  182.       OvrOpts = readln('opts')
  183.       close('opts')
  184.    end
  185.    else
  186.       OvrOpts = '-m0 '
  187.  
  188.    Opts = OvrOpts||ExtOpts
  189.  
  190. return Opts
  191.  
  192. /*--------------------------------------------------------------------------*/
  193.  
  194. ExitIt:
  195.  
  196.    exit
  197.  
  198. return
  199.  
  200.