[Toybox] sort -V
Rob Landley
rob at landley.net
Wed Dec 19 13:44:55 PST 2018
On 12/19/18 3:01 PM, enh wrote:
>> Hmmm... 4.20-rc7 is before 4.20, but 4.20-rc7-10 is _after_ 4.20-rc7.
>>
>> Grumble grumble. It's all horrible heuristics, but I would like to find some
>> simple horrible heuristics that work with the cases we care about.
>
> doesn't that then mean that the world has *4* variants of this?
> (strverscmp, coreutils, debian packages, and toybox?)
The problem is the world currently has several _thousand_ variants of this.
Nobody names packages consistently! There isn't a standard!
> (actually, autoconf already has a hacked-up replacement with a comment
> about `sort -V` not being universally available.)
>
> but don't listen to me... something is better than nothing :-)
Five.
I'm trying to come up with something simple. Something vaguely like:
thingy(char *a, char *b)
{
while (*a && *b) {
while (*a && *a == *b) a++, b++;
if (isdigit(*a) && isdigit(*b)) {
long long aa = strtoll(a, &a, 10), bb = strtoll(b, &b, 10);
if (aa<bb) return -1;
if (aa>bb) return 1;
} else {
// maybe hack for _pre and _rc here?
char c = *a ? *a : a[-1], d = *b ? *b : b[-1];
if (c == d) a++, b++;
else {
if (c<d && !strstart(&b, "-rc")) return -1;
else return 1;
}
}
return *a ? !!*b : -1;
}
Rob
More information about the Toybox
mailing list