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

  1. /*rx
  2.  *
  3.  * PrintLhAFiles.rexx - Extract and print a file from an LhA archive previously
  4.  *                     listed in a DOpus window by ListLha.rexx.
  5.  *
  6.  *                     Also allows printing of the buffer window (archive
  7.  *                     contents)
  8.  *
  9.  * $VER: PrintLhAFiles 40.1 (23/05/94) by Geoff Seeley
  10.  *
  11.  * Usage: ARexx command PrintLhAFiles.rexx (from DOpus)
  12.  *
  13.  */
  14.  
  15. /*----- Configuration Variables (change these to suit your setup) ----------*/
  16.  
  17. LhaCommand   = 'XFH_Work:C/Archivers/File/LhA '
  18. OutputWindow = '>CON:30/145/640/100/LhA_Output/CLOSE/SCREENDOPUS.1 '
  19. TmpDir       = 'T:'
  20.  
  21. /*--------------------------------------------------------------------------*/
  22.  
  23. /* misc. variables */
  24.  
  25. DOpusPort = 'DOPUS.1'
  26.  
  27. LhaExtractCmd  = '-x x '
  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. signal on failure
  42.  
  43. TopText "Print File(s) From an LhA Archive Buffer"
  44.  
  45. Busy on
  46.  
  47. /* get the path/name of the LhA archive file */
  48.  
  49. 'Status 14 -1'
  50. LhaArchive = result
  51.  
  52. /* make sure it's an LhA archive listing buffer */
  53.  
  54. if (IsLhAFile(LhaArchive) = 0) then do
  55.  
  56.    /* try other window */
  57.  
  58.    OtherWindow
  59.    'Status 14 -1'
  60.    LhaArchive = Result
  61.  
  62.    if (IsLhAFile(LhaArchive) = 0) then do
  63.  
  64.       Notify "Sorry, no LhA archive buffer found.\You must use the ListLha button first."
  65.       call CleanUp
  66.  
  67.    end
  68.  
  69. end
  70.  
  71. /* get path to archive */
  72.  
  73. call FindLhaPath
  74. LhaArchive = LhaPath || LhaArchive
  75.  
  76. /* check for existance of archive */
  77.  
  78. if ~exists(LhaArchive) then do
  79.  
  80.    Notify "Can't seem to find '" || LhaArchive || "'\Aborting."
  81.    call CleanUp
  82.  
  83. end
  84.  
  85. /* get list of selected entries */
  86.  
  87. GetSelectedAll
  88. SelectedEntries = result
  89.  
  90. /* if none selected, ask to print the window */
  91.  
  92. if SelectedEntries = 'RESULT' then do
  93.  
  94.    Request "Print LhA Buffer Contents?"
  95.  
  96.    if result = 1 then do
  97.       Busy on
  98.       'PrintDir -1'
  99.       TopText "Finished Printing LhA Buffer Window."
  100.    end
  101.    else do
  102.       Busy off
  103.       TopText "Printing LhA Buffer Window Aborted."
  104.    end
  105.  
  106.    call CleanUp
  107. end
  108.  
  109. NumberOfEntries = words(SelectedEntries)
  110.  
  111. /* ask whether to print the buffer or the selected files */
  112.  
  113. call SetRequester
  114. Request "Print Buffer Window or Selected Files?"
  115. PrintWhat = RESULT
  116. call RestoreRequester
  117.  
  118. if PrintWhat = 1 then do
  119.    'PrintDir -1'
  120.    TopText "Finished Printing LhA Buffer Window."
  121.    call CleanUp
  122. end
  123.  
  124. /* extract and print the files */
  125.  
  126. call PrintFileList
  127.  
  128. TopText "Finished Printing Selected File(s) From LhA Archive."
  129.  
  130. call CleanUp
  131.  
  132. exit
  133.  
  134. /*---------------------------------------------------------------------------*/
  135.  
  136. PrintFileList: /* extract and Print each file */
  137.  
  138.  
  139.    do EntryNumber = 1 to NumberOfEntries
  140.  
  141.       /* get entry */
  142.  
  143.       Index = word(SelectedEntries, EntryNumber)
  144.  
  145.       GetEntry Index + 1
  146.       Entry = result
  147.  
  148.       /* grab file name/path, protect in quotes */
  149.  
  150.       File = substr(Entry, 10)
  151.  
  152.       /* make sure user see's the entry */
  153.  
  154.       ScrollToShow Index
  155.  
  156.       /* put it in the file list */
  157.  
  158.       call ReplaceMetaChars
  159.       ExtractFile = File
  160.  
  161.       /* deselect this entry */
  162.  
  163.       selection = Index ||' '|| 0 ||' '|| 1
  164.       SelectEntry selection
  165.  
  166.       /* form CLI command and delete the file(s) */
  167.  
  168.       TopText 'Extracting "'||GetFileInPath(ExtractFile)||'"... Please Wait.'
  169.  
  170.       /* toast possible old file */
  171.  
  172.       pragma(Directory, TmpDir)
  173.  
  174.       if exists(ExtractFile) then
  175.          delete(ExtractFile)
  176.  
  177.       CliCommand = LhaCommand||LhaExtractCmd||Quote(LhaArchive)
  178.       CliCommand = CliCommand||' '||Quote(ExtractFile)
  179.  
  180.       address COMMAND CliCommand
  181.  
  182.       /* Print the file */
  183.  
  184.       TopText 'Printing "'||GetFileInPath(ExtractFile)||'"... Please Wait.'
  185.  
  186.       FEx = GetFileExt(File)
  187.       FBs = upper(GetFileInPath(ExtractFile))
  188.  
  189.       /* call DOpus print module */
  190.  
  191.       'Print '||Quote(TmpDir||ExtractFile)
  192.  
  193.    end
  194.  
  195. return
  196.  
  197. /*---------------------------------------------------------------------------*/
  198.  
  199. GetFileExt: procedure /* return file extension, or null */
  200.  
  201.    parse arg BFileName
  202.  
  203.    lps = lastpos(".", BFileName)               
  204.  
  205.    BFileName = StripQuotes(BFileName)
  206.  
  207.    if lps ~= 0 then                           
  208.       return(upper(right(BFileName,length(BFileName)-lps)))
  209.  
  210. return ""
  211.  
  212.  
  213. /*---------------------------------------------------------------------------*/
  214.  
  215. GetFileInPath: procedure /* return file from path */
  216.  
  217.    parse arg FilePath
  218.    if lastpos('/', FilePath) = 0 then
  219.       return FilePath
  220.    DivPos = max(lastpos(':', FilePath),lastpos('/', FilePath)) +1
  221.    parse var FilePath PathSpec =DivPos FileName
  222.    Filename = StripQuotes(Filename)
  223.  
  224. return Filename
  225.  
  226. /*---------------------------------------------------------------------------*/
  227.  
  228. IsLhAFile: procedure   /* look at extension, return 1 if right, else 0 */
  229.  
  230.    parse arg AFileName
  231.  
  232.    FileExt = GetFileExt(AFileName)
  233.  
  234.    if FileExt ~= "LHA" & FileExt ~= "LZH" then
  235.       return 0
  236.    else
  237.       return 1
  238.  
  239. return 0
  240.  
  241. /*---------------------------------------------------------------------------*/
  242.  
  243. DeletePath: procedure
  244.  
  245.    parse arg FilePath
  246.  
  247.    x = pos('/', FilePath)
  248.  
  249.    if x = 0 then
  250.       return
  251.  
  252.    CliCommand = 'C:Delete '||Quote(substr(FilePath, 1, x))||' ALL'
  253.    address COMMAND CliCommand
  254.  
  255. return
  256.  
  257. /*---------------------------------------------------------------------------*/
  258.  
  259. ReplaceMetaChars: /* replace special wildcards with ? */
  260.  
  261.    File = translate(File, '?????', '()`', '?')
  262.  
  263. return
  264.  
  265. /*---------------------------------------------------------------------------*/
  266.  
  267. FindLhAPath: /* grab invisible file path to archive */
  268.  
  269.    /* find number of entries, path is the last one */
  270.  
  271.    'Status 6 -1'
  272.  
  273.    GetEntry Result
  274.    LhaPath = Result
  275.  
  276. return
  277.  
  278. /*---------------------------------------------------------------------------*/
  279.  
  280. Quote: procedure /* add quotes to string */
  281.  
  282.    parse arg string
  283.  
  284. return '"'||string||'"'
  285.  
  286. /*---------------------------------------------------------------------------*/
  287.  
  288. StripQuotes: procedure /* strip quotes from string */
  289.  
  290.    parse arg string
  291.  
  292. return strip(string,, '"')
  293.  
  294. /*---------------------------------------------------------------------------*/
  295.  
  296. failure: /* most likely a failed COMMAND */
  297.  
  298.    Notify "Print command failed. The archive is probably corrupt."
  299.  
  300.    Busy off
  301.  
  302.    exit
  303.  
  304. return
  305.  
  306. /*--------------------------------------------------------------------------*/
  307.  
  308. GetWord: procedure /* get word from '|' separated string */
  309.  
  310.   parse arg number,words
  311.  
  312.   if(left(words,1) ~= '|') then
  313.      words = '|'||words
  314.  
  315.   do i=1 to number
  316.      idx = index(words, '|');
  317.      words = substr(words, idx+1)
  318.   end
  319.  
  320.   end = index(words, '|') - 1
  321.  
  322.   if words = "" then
  323.      return ""
  324.  
  325.   ret_str = substr(words, 1, end)
  326.  
  327. return ret_str
  328.  
  329. /*--------------------------------------------------------------------------*/
  330.  
  331. CountWords: procedure /* count words from '|' separated string */
  332.  
  333.    parse arg words
  334.  
  335.    count = 0
  336.    idx = index(words, '|')
  337.  
  338.    do while idx ~= 0
  339.      count = count + 1
  340.      words = substr(words, idx+1)
  341.      idx = index(words, '|')
  342.    end
  343.  
  344. return count
  345.  
  346. /*---------------------------------------------------------------------------*/
  347.  
  348. SetRequester:  /* set requester strings */
  349.                                       
  350.    'Status 26 set Buffer'                
  351.    'Status 27 set Files'                 
  352.                                       
  353. return
  354.  
  355. /*---------------------------------------------------------------------------*/
  356.  
  357. RestoreRequester: /* restore (default) requester strings */
  358.                                                            
  359.    Busy On                                                 
  360.    'Status 26 set Okay'                                    
  361.    'Status 27 set Cancel'                                  
  362.                                                            
  363. return
  364.  
  365. /*---------------------------------------------------------------------------*/
  366.  
  367. CleanUp: /* clean up files and exit */
  368.  
  369.    ExtractFile = StripQuotes(ExtractFile)
  370.  
  371.    pragma(Directory, TmpDir)
  372.    if exists(ExtractFile) then do
  373.       delete(ExtractFile)
  374.       call DeletePath(ExtractFile)
  375.    end
  376.  
  377.    Busy off
  378.  
  379.    exit
  380.  
  381. return
  382.  
  383.