home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of Mecomp Multimedia 1
/
Mecomp-CD.iso
/
amiga
/
tools
/
opus
/
opus-tools_4.x
/
arexx
/
printlhafiles.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1994-07-01
|
8KB
|
383 lines
/*rx
*
* PrintLhAFiles.rexx - Extract and print a file from an LhA archive previously
* listed in a DOpus window by ListLha.rexx.
*
* Also allows printing of the buffer window (archive
* contents)
*
* $VER: PrintLhAFiles 40.1 (23/05/94) by Geoff Seeley
*
* Usage: ARexx command PrintLhAFiles.rexx (from DOpus)
*
*/
/*----- Configuration Variables (change these to suit your setup) ----------*/
LhaCommand = 'XFH_Work:C/Archivers/File/LhA '
OutputWindow = '>CON:30/145/640/100/LhA_Output/CLOSE/SCREENDOPUS.1 '
TmpDir = 'T:'
/*--------------------------------------------------------------------------*/
/* misc. variables */
DOpusPort = 'DOPUS.1'
LhaExtractCmd = '-x x '
if ~show(l,"rexxsupport.library") then
call addlib("rexxsupport.library",0,-30,0)
/* make sure we've got somebody to talk to */
if showlist('Ports', DOpusPort) = 0 then do
say 'Directory Opus ARexx port not found. Aborting.'
call CleanUp
end
address 'DOPUS.1'
options results
signal on failure
TopText "Print File(s) From an LhA Archive Buffer"
Busy on
/* get the path/name of the LhA archive file */
'Status 14 -1'
LhaArchive = result
/* make sure it's an LhA archive listing buffer */
if (IsLhAFile(LhaArchive) = 0) then do
/* try other window */
OtherWindow
'Status 14 -1'
LhaArchive = Result
if (IsLhAFile(LhaArchive) = 0) then do
Notify "Sorry, no LhA archive buffer found.\You must use the ListLha button first."
call CleanUp
end
end
/* get path to archive */
call FindLhaPath
LhaArchive = LhaPath || LhaArchive
/* check for existance of archive */
if ~exists(LhaArchive) then do
Notify "Can't seem to find '" || LhaArchive || "'\Aborting."
call CleanUp
end
/* get list of selected entries */
GetSelectedAll
SelectedEntries = result
/* if none selected, ask to print the window */
if SelectedEntries = 'RESULT' then do
Request "Print LhA Buffer Contents?"
if result = 1 then do
Busy on
'PrintDir -1'
TopText "Finished Printing LhA Buffer Window."
end
else do
Busy off
TopText "Printing LhA Buffer Window Aborted."
end
call CleanUp
end
NumberOfEntries = words(SelectedEntries)
/* ask whether to print the buffer or the selected files */
call SetRequester
Request "Print Buffer Window or Selected Files?"
PrintWhat = RESULT
call RestoreRequester
if PrintWhat = 1 then do
'PrintDir -1'
TopText "Finished Printing LhA Buffer Window."
call CleanUp
end
/* extract and print the files */
call PrintFileList
TopText "Finished Printing Selected File(s) From LhA Archive."
call CleanUp
exit
/*---------------------------------------------------------------------------*/
PrintFileList: /* extract and Print each file */
do EntryNumber = 1 to NumberOfEntries
/* get entry */
Index = word(SelectedEntries, EntryNumber)
GetEntry Index + 1
Entry = result
/* grab file name/path, protect in quotes */
File = substr(Entry, 10)
/* make sure user see's the entry */
ScrollToShow Index
/* put it in the file list */
call ReplaceMetaChars
ExtractFile = File
/* deselect this entry */
selection = Index ||' '|| 0 ||' '|| 1
SelectEntry selection
/* form CLI command and delete the file(s) */
TopText 'Extracting "'||GetFileInPath(ExtractFile)||'"... Please Wait.'
/* toast possible old file */
pragma(Directory, TmpDir)
if exists(ExtractFile) then
delete(ExtractFile)
CliCommand = LhaCommand||LhaExtractCmd||Quote(LhaArchive)
CliCommand = CliCommand||' '||Quote(ExtractFile)
address COMMAND CliCommand
/* Print the file */
TopText 'Printing "'||GetFileInPath(ExtractFile)||'"... Please Wait.'
FEx = GetFileExt(File)
FBs = upper(GetFileInPath(ExtractFile))
/* call DOpus print module */
'Print '||Quote(TmpDir||ExtractFile)
end
return
/*---------------------------------------------------------------------------*/
GetFileExt: procedure /* return file extension, or null */
parse arg BFileName
lps = lastpos(".", BFileName)
BFileName = StripQuotes(BFileName)
if lps ~= 0 then
return(upper(right(BFileName,length(BFileName)-lps)))
return ""
/*---------------------------------------------------------------------------*/
GetFileInPath: procedure /* return file from path */
parse arg FilePath
if lastpos('/', FilePath) = 0 then
return FilePath
DivPos = max(lastpos(':', FilePath),lastpos('/', FilePath)) +1
parse var FilePath PathSpec =DivPos FileName
Filename = StripQuotes(Filename)
return Filename
/*---------------------------------------------------------------------------*/
IsLhAFile: procedure /* look at extension, return 1 if right, else 0 */
parse arg AFileName
FileExt = GetFileExt(AFileName)
if FileExt ~= "LHA" & FileExt ~= "LZH" then
return 0
else
return 1
return 0
/*---------------------------------------------------------------------------*/
DeletePath: procedure
parse arg FilePath
x = pos('/', FilePath)
if x = 0 then
return
CliCommand = 'C:Delete '||Quote(substr(FilePath, 1, x))||' ALL'
address COMMAND CliCommand
return
/*---------------------------------------------------------------------------*/
ReplaceMetaChars: /* replace special wildcards with ? */
File = translate(File, '?????', '()`', '?')
return
/*---------------------------------------------------------------------------*/
FindLhAPath: /* grab invisible file path to archive */
/* find number of entries, path is the last one */
'Status 6 -1'
GetEntry Result
LhaPath = Result
return
/*---------------------------------------------------------------------------*/
Quote: procedure /* add quotes to string */
parse arg string
return '"'||string||'"'
/*---------------------------------------------------------------------------*/
StripQuotes: procedure /* strip quotes from string */
parse arg string
return strip(string,, '"')
/*---------------------------------------------------------------------------*/
failure: /* most likely a failed COMMAND */
Notify "Print command failed. The archive is probably corrupt."
Busy off
exit
return
/*--------------------------------------------------------------------------*/
GetWord: procedure /* get word from '|' separated string */
parse arg number,words
if(left(words,1) ~= '|') then
words = '|'||words
do i=1 to number
idx = index(words, '|');
words = substr(words, idx+1)
end
end = index(words, '|') - 1
if words = "" then
return ""
ret_str = substr(words, 1, end)
return ret_str
/*--------------------------------------------------------------------------*/
CountWords: procedure /* count words from '|' separated string */
parse arg words
count = 0
idx = index(words, '|')
do while idx ~= 0
count = count + 1
words = substr(words, idx+1)
idx = index(words, '|')
end
return count
/*---------------------------------------------------------------------------*/
SetRequester: /* set requester strings */
'Status 26 set Buffer'
'Status 27 set Files'
return
/*---------------------------------------------------------------------------*/
RestoreRequester: /* restore (default) requester strings */
Busy On
'Status 26 set Okay'
'Status 27 set Cancel'
return
/*---------------------------------------------------------------------------*/
CleanUp: /* clean up files and exit */
ExtractFile = StripQuotes(ExtractFile)
pragma(Directory, TmpDir)
if exists(ExtractFile) then do
delete(ExtractFile)
call DeletePath(ExtractFile)
end
Busy off
exit
return