I'm trying to figure out how to check on a version of a library and to do an action on it from the startup-sequence i.e. dos script.
This is what I need (pseudo):
$ver = version >NIL: some.library if $ver EQ "1.1" #execute program endif if $ver EQ "1.2" #execute program endif if $ver EQ "1.3" #execute program endif
I've been playing around with the well known 'if not warn' construction but it doesn't work well. It always assumes that a lower version is also OK if a higher version was found.
For example (does not work):
version >NIL: some.library version=1 revision=1 if not warn #execute program else version >NIL: some.library version=1 revision=2 if not warn #execute program else version >NIL: some.library version=1 revision=2 if not warn #execute program endif endif endif
The problem with above is that when you have library 2.0 every version check results in OK because version assumes that if you have a newer it also OK if you have an older and it results in an OK.
There must be another better and more clean way..... anyone?
Note: Ideally it would be nice to capture the version number and put it in an variable and then evaluate the variable.
version >NIL: some.library version=1 revision=3 if not warn ; we have version 1.3 or newer else version >NIL: some.library version=1 revision=2 if not warn ; we have version 1.2 else version >NIL: some.library version=1 revision=1 if not warn ; we have version 1.1 else ; we have a version older than 1.1 endif endif endif
Status: Offline
sananaman
Re: Startup-Sequence if then else version check Posted on 13-May-2012 11:14:40
version >NIL: some.library version=1 revision=5 if not warn ; we have version 1.5 or newer else version >NIL: some.library version=1 revision=4 if not warn ; we have version 1.4 else version >NIL: some.library version=1 revision=1 if not warn ; we have version 1.1, 1.2 or 1.3 else version >NIL: some.library version=1 revision=0 if not warn ; we have version 1.0 else version >NIL: some.library version=0 revision=9 if not warn ; we have version 0.9 else ; we have version 0.8 or older endif endif endif endif endif
Status: Offline
tbreeden
Re: Startup-Sequence if then else version check Posted on 13-May-2012 13:30:23
Don't know how you're testing this but it's worth noting that the version will by default first check for the library in memory before it will check for a file on disk, so if some program has the library loaded in memory and you test just by replacing the file in LIBS: then you might not get the result you expect.
In order to force "version" to get the version information from the file on disk you can use the "file" switch.
Status: Offline
salass00
Re: Startup-Sequence if then else version check Posted on 13-May-2012 18:07:35
That's more or less what I suggested above but he claims that it doesn't work (it should work since it checks for higher version numbers first before lower ones unlike sananaman's version which checks them in the wrong order and doesn't work for obvious reasons).
Status: Offline
Xenic
Re: Startup-Sequence if then else version check Posted on 13-May-2012 23:35:53
Joined: 2-Feb-2004 Posts: 1246
From: Pennsylvania, USA
@sananaman Quote:
There must be another better and more clean way..... anyone? Note: Ideally it would be nice to capture the version number and put it in an variable and then evaluate the variable.
If you want to match exact versions then your pseudo code is close. See if this works:
;AmigaDOS Script Set library libs:some.library If EXISTS $library Set version `Version *>NIL: file $library` If "$version" EQ "some.library 1.1" ; #execute program skip done Endif If "$version" EQ "some.library 1.2" ; #execute program skip done Endif If "$version" EQ "some.library 1.3" ; #execute program skip done Endif lab done Unset version Endif Unset library
Last edited by Xenic on 14-May-2012 at 06:52 PM. Last edited by Xenic on 13-May-2012 at 11:39 PM.
_________________ X1000 with 2GB memory & OS4.1FE
Status: Offline
Toaks
Re: Startup-Sequence if then else version check Posted on 14-May-2012 6:17:52
@All that helped: Guys I really would like to thank you all for thinking about solutions the get a nice script.
My personal opinion is that Xenic got the most clean code solution. Al the others are too much nesting of 'if then else' inside 'if then else'. It doesn't look clean and it's too easy to make a mistakes. But thanks for the thinking work anyway.
@Xenic: On my system this part doesn't work:
Set version `Version *>NIL: file $library` (This raises an error messge).
It needs to be:
Set version `Version file $library`
As the result (no matter what it will be) will be placed in the variable 'version' anyway. I've also changed the 'version' variable in something else to avoid confusion.
And if you only want to evaluate on 'version number' instead of 'some.libary versionnumber' then you might want to use the trick of tbreeden. Altough I've not tested this in real.