.key LHAARC/A,LZXARC/A,FORCE/S,OPT1,OPT2,OPT3
.bra {
.ket }

; $VER: lha2lzx 1.1 (01.04.95) by Ralph Seichter
;
; This script will unpack a LhA archive and re-pack its contents using
; the LZX archiver. It will display the file sizes and the user can
; decide which archive is to be kept. There is also a forced mode, in
; which there is no user interaction (the LhA archive will always be
; replaced by the LZX archive).
;
; INSTALLATION:
;
; You should copy lha2lzx to your S: directory or any other directory
; in your command path. Make surce that the script bit is set, or you
; will have to invoke it with "Execute lha2lzx".
;
; USAGE EXAMPLE:
;
; Best compression is obtained by invoking the script as follows:
;
;      lha2lzx foo.lha bar.lzx -3
;
; Please note that lha2lzx will use the exakt LZX name you specify, as
; the -X0 option (don't append suffix) is used. If you want the usual
; suffix .lzx, make sure to type it!
;
; If you want to re-pack all archives in a directory, use lha2lzx-dir,
; this script is also included in the distribution archive.

set tempname lha2lzx-$process
set tempdir T:

failat 30
makedir $tempdir$tempname
if warn
	echo "Can't create directory $tempdir"
	quit 5
endif
lha -I -F -M -a -P-1 x {LHAARC} $tempdir$tempname/
if warn
	echo "Can't unpack {LHAARC}"
	delete $tempdir$tempname all force quiet
	quit 5
endif
failat 20

assign $tempname: ""
cd $tempdir$tempname
; This is a multitasking OS, so I run lzx with priority -1
lzx -r -a -e -F -Y -P-1 -X0 {OPT1} {OPT2} {OPT3} a $tempname:{LZXARC} #?
cd $tempname:
assign $tempname:
delete $tempdir$tempname all force quiet

echo "Testing archive integrity... " noline
failat 11
lzx -q -X0 t {LZXARC}
if warn
	echo "{LZXARC} is corrupt!"
	delete {LZXARC} quiet
	quit 5
else
	echo "ok"
endif
failat 10

echo "*N=== Archive size comparison =========="
list lformat "%-24N %7L bytes" {LHAARC} {LZXARC}

if "{FORCE}" eq ""
	; Script is interactive
	ask "*NKeep {LHAARC} (y/N)?"
	if warn
		ask "Delete {LZXARC} (y/N)?"
		if warn
			delete {LZXARC} force
		endif
	else
		delete {LHAARC} force
	endif
else
	; Script is NOT interactive
	delete {LHAARC} force
endif

unset tempdir
unset tempname

; EOF
