Skip to content
Permalink
3da509e008
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
125 lines (95 sloc) 2.78 KB
/*
** beeversion - compare bee package versionnumbers
**
** Copyright (C) 2009-2016
** Marius Tolzmann <m@rius.berlin>
** Tobias Dreyer <dreyer@molgen.mpg.de>
** and other bee developers
**
** This file is part of bee.
**
** bee is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "bee_version.h"
// '2.23.2' > '2.23.0'
//' 2.23.10' > '2.23.8'
// '2.23.001' == '2.23.1'
// '2.23.1001' > '2.23.101'
int compare_version_strings(char *a, char *b) {
while (1) {
if (isdigit(*a) && isdigit (*b)) {
long i_a = atoll(a);
long i_b = atoll(b);
if (i_a < i_b)
return -1;
if (i_a > i_b)
return 1;
while(isdigit(*a))
a++;
while(isdigit(*b))
b++;
continue;
}
if (*a < *b)
return -1;
if (*a > *b)
return 1;
if (*a == '\0') // implies *b == '\0', too
return 0;
a++;
b++;
}
}
int compare_beepackage_names(struct beeversion *v1, struct beeversion *v2) {
int ret;
assert(v1);
assert(v2);
assert(v1->pkgname);
assert(v2->pkgname);
assert(v1->subname);
assert(v2->subname);
ret = strcmp(v1->pkgname, v2->pkgname);
if(!ret)
ret = strcmp(v1->subname, v2->subname);
return(ret);
}
int compare_beeversions(struct beeversion *v1, struct beeversion *v2) {
int ret;
assert(v1);
assert(v2);
ret = compare_version_strings(v1->version, v2->version);
if(ret)
return(ret);
if(v1->extraversion_typ < v2->extraversion_typ)
return(-1);
if(v1->extraversion_typ > v2->extraversion_typ)
return(1);
ret = compare_version_strings(v1->extraversion_nr, v2->extraversion_nr);
if(ret)
return(ret);
ret = compare_version_strings(v1->pkgrevision, v2->pkgrevision);
return ret;
}
int compare_beepackages(struct beeversion *v1, struct beeversion *v2) {
int ret;
assert(v1);
assert(v2);
ret = compare_beepackage_names(v1, v2);
if(!ret)
ret = compare_beeversions(v1, v2);
return(ret);
}