- Subject: Re: [slang-users] Version compare
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Mon, 14 May 2007 12:55:45 -0400
=?UTF-8?Q?J=C3=B6rg?= Sommer <joerg@xxxxxxxxxxxx> wrote:
>I want to add a workaround for SLang version before pre2.0.7-21. But how
>do I check for those version?
I would not bother worrying about "pre" releases since they reflect
snapshots that one has taken from SVN repository and do not represent
an announced release. Nevertheless if your want to include this
possibility in your test, you should create a function to perform the
comparision and use that, e.g.,
#if (slang_version_lt("pre2.0.7-4"))
workaround ();
#else
real_code ();
#endif
Here slang_version_lt is defined as follows:
private define parse_slang_version (v)
{
variable major, minor, patch, pre;
if (4 == sscanf (v, "pre%d.%d.%d-%d", &major, &minor, &patch, &pre))
return (major, minor, patch, pre);
if (3 != sscanf (v, "%d.%d.%d", &major, &minor, &patch))
throw InternalError, "Unexpected version number format";
return major, minor, patch, 0;
}
% Returns < 0 if _slang_version < version
% == 0 if _slang_version == version
% > 0 if _slang_version > version
define slang_version_cmp (version)
{
variable maj0, min0, pat0, pre0;
variable maj1, min1, pat1, pre1;
(maj0, min0, pat0, pre0) = parse_slang_version (_slang_version_string);
(maj1, min1, pat1, pre1) = parse_slang_version (version);
variable v0 = maj0*10000 + min0*100 + pat0;
variable v1 = maj1*10000 + min1*100 + pat1;
if (v0 != v1) return v0 - v1;
if (pre0 == 0) return 1;
if (pre1 == 0) return -1;
return pre0 - pre1;
}
define slang_version_lt (version)
{
return slang_version_cmp (version) < 0;
}
define slang_version_le (version)
{
return slang_version_cmp (version) <= 0;
}
define slang_version_gt (version)
{
return slang_version_cmp (version) > 0;
}
define slang_version_ge (version)
{
return slang_version_cmp (version) >= 0;
}
--John
[2007 date index]
[2007 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]