home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
opus
/
v4
/
arexx
/
listlha.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1977-12-31
|
7KB
|
284 lines
/*rx
*
* ListLhA.rexx - List and display an LhA archive file in a DOpus window
* (companion script ExtractLhaFiles.rexx will allow the user
* to select and extract files to the destination window)
*
* $VER: ListLhA 40.6 (22/05/94) by Geoff Seeley
*
* Usage: ARexx command ListLhA.rexx (from DOpus)
*
*/
/* configuration variables (change these to suit your setup) */
LhaCommand = 'sys:C/LhA -x -m v '
LhaOutput = 'T:lha_out'
/*---------------NO USER SERVICABLE PARTS BELOW :-)----------------------------*/
/* misc. variables */
DOpusPort = 'DOPUS.1'
HandlerPort = 'LHALIST.1'
LhaHeader = '--------'
userdata = ' 0' /* default */
fgpen = ' 1' /* palette 1 */
bgpen = ' 0' /* palette 2 */
selectable = ' 1' /* can select */
unselectable = ' 0' /* can't select */
show = ' 0' /* update win */
before = ' -1' /* add to end */
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
else do
/* make sure DOpus is listening to us... */
address 'DOPUS.1'
options results
/* get some information from DOpus */
Status 3
CurrentWindow = Result
/* check if window is already and LhA archive */
Status 14 CurrentWindow
LhaFileName = Result
/* if we don't see the proper extension, look at file in window */
if (IsLhAFile(LhaFileName) = 0) then do
/* get name of LhA archive file selected */
GetNextSelected CurrentWindow
LhaFileName = result
/* make sure its got the right extension */
if (IsLhAFile(LhaFileName) = 0) then do
Notify "Sorry, You *must* select an archive file\ending with '.LHA' or '.LZH'\Aborting."
TopText "List LhA archive aborted."
call CleanUp
end
/* get the directory of the LhA archive */
Status 13 CurrentWindow
LhaFilePath = result
/* make a full path/filename from above */
LhaArchive = LhaFilePath || LhaFileName
end
else do
/* get path to archive, check if it exists */
call FindLhAPath
LhaArchive = LhaFilePath || LhaFileName
if ~exists(LhaArchive) then do
Notify "Can't find LhA archive " || LhaArchive
call CleanUp
end
end
end
/* setup DOpus window and tell user what's happening */
ClearWin CurrentWindow
SetWinTitle LhaFileName
Busy on
TopText "Getting List of File(s) From Archive. Please Wait..."
/* make a listing file from the archive so we can parse it... */
CliString = LhaCommand || Quote(LhaArchive) || ' > ' || LhaOutput
address command CliString
/* parse the list of LhA files */
TopText "Parsing File(s). Please Wait..."
call ParseLhaList
'DisplayDir -1'
/* if handler is running, attach a custom handler to the window */
if show('p', HandlerPort) then
'AddCustHandler '||HandlerPort||' -1'
/* That's all folks... */
Totals = "Files: 0/"||FileNumber-1||" Bytes: 0/"||strip(TotalBytes)
TopText Totals
Busy off
call CleanUp
exit
/*---------------------------------------------------------------------------*/
ParseLhaList: /* open the listing file, and parse it */
if open(LhaList, LhaOutput, 'R') then do
/* skip the header */
junk = ''
do while left(junk, 8, '') ~= LhaHeader & ~eof(LhaList)
junk = readln(LhaList)
end
if eof(LhaList) then do
/* what the hell?? Abort. */
Notify "No files found in selected LhA archive\Aborting."
call CleanUp
end
/* read in list of files */
FileNumber = 1
line = ''
FName = ""
do while line ~= LhaHeader & ~eof(LhaList)
line = readln(LhaList)
if left(line, 1) = ':' then
iterate
if substr(line, 1, 6) = '0d'x||" " then do
Notify FName||"\"||substr(line, 7, (length(line)-9))
iterate
end
if left(line, 8, '') = LhaHeader then
leave
FileNumber = FileNumber + 1
FSize = substr(line, 1, 8)
FName = substr(line, 44)
File = FSize||' '||FName
File = Quote(File)
Entry = File || userdata || fgpen || bgpen || selectable || show || before
AddCustEntry Entry
end
/* grab totals */
TotalsLine = readln(LhaList)
close(LhaList)
/* add two unselectable entries for the totals */
File = Quote(LhaHeader)
Entry = File || userdata || fgpen || bgpen || unselectable || show || before
AddCustEntry Entry
FSize = substr(TotalsLine, 1, 8)
TotalBytes = FSize
FName = substr(TotalsLine, 44)
File = '"'||FSize||' '||FName||'"'
Entry = File || userdata || fgpen || bgpen || unselectable || show || before
AddCustEntry Entry
/* add invisible entry giving us the path */
File = Quote(LhaFilePath)
Entry = File || userdata || bgpen || bgpen || unselectable || show || before
AddCustEntry Entry
end
else do
TopText "Can't open temp file " || LhaOutput
call CleanUp
end
return
/*--------------------------------------------------------------------------*/
IsLhAFile: procedure /* look at extension, return 1 if right, else 0 */
parse arg AFileName
lps = lastpos(".", AFileName)
if lps = 0 then
return 0
FileExt = upper(right(AFileName,length(AFileName)-lps))
if FileExt ~= "LHA" & FileExt ~= "LZH" then
return 0
else
return 1
return 0
/*--------------------------------------------------------------------------*/
FindLhAPath: /* grab invisible file path to archive */
/* find number of entries, path is the last one */
'Status 6 -1'
GetEntry Result
LhaFilePath = 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,, '"')
/*---------------------------------------------------------------------------*/
CleanUp: /* Remove any files and exit */
if exists(LhaOutput) then
delete(LhaOutput)
Busy off
exit
return