Thursday, March 21, 2019

Adapting ViewLHA to run on Icaros /2

Today I decided to turn back to yesterday's ViewLHA/vlha combo, to refine their behaviour. There were, in fact, some little quirks I could simply not live with. For starter, the fact that the resulting drawer in T: would include the relative path you used for the viewlha command. For instance, if you wanted to explore images included in the 'test.lha' archive, stored in sys:MyWorkspace/Pictures, and you gave a command like this one from a different directory:

AROS:> viewlha MyWorkspace/Pictures/test.lha

You'd get the contents of test.lha in the following directory, T:MyWorkspace/Pictures/test.lha/. Why? That's logical. Please let me recall yesterday syntax for the LHA command:

lha -xw=t:{fname} "{fname}"

if {fname} is "MyWorkspace/Pictures/test.lha", LHA will recreate that path when trying to create a directory with that (whole) name. I needed to separate the file name from its path and, luckily, the LIST command can do that quite easily. Icaros has also other tools to do that, but LIST should be easier to use also on other AROS implementations. The following command places the file name part of {fname} to a new temporary text file called T:arcname.

List LFORMAT="%N" "{fname}" >t:arcname

Now, let's change the LHA and ZuneView lines to reflect this change:

lha -xw=t:${T:arcname} "{fname}" >NIL:
sys:utilities/zuneview/zuneview "t:${T:arcname}" >NIL:

...and we're done! This issue is solved. The current vlha script is now like this:

.key fname/a
.BRA {
.KET }

; let's separate archive name from its path
List LFORMAT="%N" "{fname}" >t:arcnam

;View a graphics file compressed with LhA
lha -xw=t:${T:arcname} "{fname}" >NIL:
sys:utilities/zuneview/zuneview "t:${T:arcname}" >NIL

; cleaning T: from temporary files
delete "T:${t:arcname}" ALL FORCE >NIL:
delete t:arcname >NIL:

(it does not handle archives with spaces is name, but I have already reported this to Mats, since it seems to be ViewLHA related).