Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CMake
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Daniel Pfeifer
CMake
Commits
04c9b5ec
There was a problem fetching the pipeline summary.
Commit
04c9b5ec
authored
7 years ago
by
Daniel Pfeifer
Browse files
Options
Downloads
Patches
Plain Diff
cmVersionComparison: Add Debian and RPM style version comparison
parent
5913e69f
Loading
Loading
No related merge requests found
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Source/cmVersionComparison.cxx
+137
-0
137 additions, 0 deletions
Source/cmVersionComparison.cxx
Source/cmVersionComparison.h
+12
-0
12 additions, 0 deletions
Source/cmVersionComparison.h
with
149 additions
and
0 deletions
Source/cmVersionComparison.cxx
+
137
−
0
View file @
04c9b5ec
...
...
@@ -39,6 +39,123 @@ int cm_vercmp_dot_decimal(const char* lhss, const char* rhss)
return
0
;
}
int
cm_vercmp_deb
(
const
char
*
str1
,
const
char
*
str2
)
{
int
r
,
c1
,
c2
;
for
(;;)
{
c1
=
*
str1
++
;
c2
=
*
str2
++
;
if
(
isdigit
(
c1
)
&&
isdigit
(
c2
))
{
while
(
c1
==
'0'
)
{
c1
=
*
str1
++
;
}
while
(
c2
==
'0'
)
{
c2
=
*
str2
++
;
}
r
=
0
;
while
(
isdigit
(
c1
)
&&
isdigit
(
c2
))
{
if
(
!
r
)
{
r
=
c1
-
c2
;
}
c1
=
*
str1
++
;
c2
=
*
str2
++
;
}
if
(
isdigit
(
c1
))
{
return
1
;
}
if
(
isdigit
(
c2
))
{
return
-
1
;
}
if
(
r
)
{
return
r
<
0
?
-
1
:
1
;
}
}
c1
=
c1
==
'~'
?
-
1
:
!
c1
||
isalnum
(
c1
)
?
c1
:
c1
+
256
;
c2
=
c2
==
'~'
?
-
1
:
!
c2
||
isalnum
(
c2
)
?
c2
:
c2
+
256
;
r
=
c1
-
c2
;
if
(
r
)
{
return
r
<
0
?
-
1
:
1
;
}
if
(
!
c1
)
{
return
0
;
}
}
}
int
cm_vercmp_rpm
(
const
char
*
str1
,
const
char
*
str2
)
{
int
r
=
0
;
const
char
*
end1
,
*
end2
;
for
(;;)
{
while
(
*
str1
&&
!
isalnum
(
*
str1
)
&&
*
str1
!=
'~'
)
{
str1
++
;
}
while
(
*
str2
&&
!
isalnum
(
*
str2
)
&&
*
str2
!=
'~'
)
{
str2
++
;
}
if
(
*
str1
&&
*
str1
==
'~'
)
{
if
(
*
str2
&&
*
str2
==
'~'
)
{
str1
++
;
str2
++
;
continue
;
}
return
-
1
;
}
if
(
*
str2
&&
*
str2
==
'~'
)
{
return
1
;
}
if
(
!*
str1
||
!*
str2
)
{
break
;
}
if
(
isdigit
(
*
str1
)
||
isdigit
(
*
str1
))
{
while
(
*
str1
==
'0'
&&
isdigit
(
str1
[
1
]))
{
str1
++
;
}
while
(
*
str2
==
'0'
&&
isdigit
(
str2
[
1
]))
{
str2
++
;
}
for
(
end1
=
str1
;
isdigit
(
*
end1
);)
{
end1
++
;
}
for
(
end2
=
str2
;
isdigit
(
*
end2
);)
{
end2
++
;
}
r
=
(
end1
-
str1
)
-
(
end2
-
str2
);
if
(
!
r
)
{
r
=
strncmp
(
str1
,
str2
,
end1
-
str1
);
}
if
(
r
)
{
return
r
>
0
?
1
:
-
1
;
}
}
else
{
for
(
end1
=
str1
;
isalpha
(
*
end1
);)
{
end1
++
;
}
for
(
end2
=
str2
;
isalpha
(
*
end2
);)
{
end2
++
;
}
r
=
(
end1
-
str1
)
-
(
end2
-
str2
);
if
(
r
>
0
)
{
r
=
strncmp
(
str1
,
str2
,
end2
-
str2
);
return
r
>=
0
?
1
:
-
1
;
}
if
(
r
<
0
)
{
r
=
strncmp
(
str1
,
str2
,
end1
-
str1
);
return
r
<=
0
?
-
1
:
1
;
}
r
=
strncmp
(
str1
,
str2
,
end1
-
str1
);
if
(
r
)
{
return
r
>
0
?
1
:
-
1
;
}
}
str1
=
end1
;
str2
=
end2
;
}
return
*
str1
?
1
:
*
str2
?
-
1
:
0
;
}
typedef
int
(
*
cm_vercmp_fun
)(
const
char
*
,
const
char
*
);
bool
cm_match
(
cm_vercmp_fun
vercmp_fun
,
const
char
*
lhss
,
Operator
op
,
const
char
*
rhss
)
...
...
@@ -151,6 +268,26 @@ bool Match(std::string const& lhs, Operator op, std::string const& rhs)
return
cm_match
(
cm_vercmp_dot_decimal
,
lhs
.
c_str
(),
op
,
rhs
.
c_str
());
}
int
CompareDEB
(
std
::
string
const
&
lhs
,
std
::
string
const
&
rhs
)
{
return
cm_vercmp_deb
(
lhs
.
c_str
(),
rhs
.
c_str
());
}
bool
MatchDEB
(
std
::
string
const
&
lhs
,
Operator
op
,
std
::
string
const
&
rhs
)
{
return
cm_match
(
cm_vercmp_deb
,
lhs
.
c_str
(),
op
,
rhs
.
c_str
());
}
int
CompareRPM
(
std
::
string
const
&
lhs
,
std
::
string
const
&
rhs
)
{
return
cm_vercmp_rpm
(
lhs
.
c_str
(),
rhs
.
c_str
());
}
bool
MatchRPM
(
std
::
string
const
&
lhs
,
Operator
op
,
std
::
string
const
&
rhs
)
{
return
cm_match
(
cm_vercmp_rpm
,
lhs
.
c_str
(),
op
,
rhs
.
c_str
());
}
int
strverscmp
(
std
::
string
const
&
lhs
,
std
::
string
const
&
rhs
)
{
return
cm_strverscmp
(
lhs
.
c_str
(),
rhs
.
c_str
());
...
...
This diff is collapsed.
Click to expand it.
Source/cmVersionComparison.h
+
12
−
0
View file @
04c9b5ec
...
...
@@ -34,6 +34,18 @@ struct CompareGreater
}
};
/**
* Debian type version compare.
*/
int
CompareDEB
(
std
::
string
const
&
lhs
,
std
::
string
const
&
rhs
);
bool
MatchDEB
(
std
::
string
const
&
lhs
,
Operator
op
,
std
::
string
const
&
rhs
);
/**
* RPM type version compare.
*/
int
CompareRPM
(
std
::
string
const
&
lhs
,
std
::
string
const
&
rhs
);
bool
MatchRPM
(
std
::
string
const
&
lhs
,
Operator
op
,
std
::
string
const
&
rhs
);
/**
* Compare two ASCII strings using natural versioning order.
* Non-numerical characters are compared directly.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment