[fpc-pascal] Comparing version numbers
A.J. Venter
aj at getopenlab.com
Fri Jun 2 23:03:07 CEST 2006
I have tried about a dozen different algorithms now, and I admit to being
stumped because everyone I've tried fails SOMEWHERE.
The task before me is to compare version numbers of software packages and
determine which is higher.
First try was to simply do a string comparison.
This almost worked, except that
4.0.12
Is asciibeticallly smaller than
4.0.1
So much for that idea then.
So I figured, let's convert them to integers, we drop any non-numeric
characters and with the rest we do just add them up, each time multyplying by
10 first.
So 4.0.12 becomes 4012 etc.
Almost worked and solved the above problem - but now:
4.0.12 -> 4012
4.1.0 -> 410
And 4.1.0 is of course supposed to be bigger.
So next plan, convert them to real's using a variation of the same theme.
So that worked a bit better, now
4.10 > 4.012
Unfortunately this has it's own problem because
4.0.7 > 4.012
(But 4.0.12 is a higher version).
I am out of ideas.
Somehow I have to treat all the parts correctly, while being compatible with
things that follow slightly different schemes (udev packages for example have
no fullstops).
The one good piece of news is that I ONLY need to compare versions of the SAME
package. So I don't have to worry about comparing 4.0.12 with udev's 070 for
example.
So the question is:
1) does somebody HAVE an algorithm for this already ?
2) If not, can somebody give me a hint about what approach to take ?
A.J.
--
"there's nothing as inspirational for a hacker as a cat obscuring a bug
by sitting in front of the monitor" - Boudewijn Rempt
A.J. Venter
Chief Software Architect
OpenLab International
www.getopenlab.com
www.silentcoder.co.za
+27 82 726 5103
More information about the fpc-pascal
mailing list