int versioncompare(const struct versionrevision *version, const struct versionrevision *refversion) { int r; if (version->epoch > refversion->epoch) return 1; if (version->epoch < refversion->epoch) return -1; r= verrevcmp(version->version,refversion->version); if (r) return r; return verrevcmp(version->revision,refversion->revision); }
/** * Compares two Debian versions. * * This function follows the convention of the comparator functions used by * qsort(). * * @see deb-version(5) * * @param a The first version. * @param b The second version. * * @retval 0 If a and b are equal. * @retval <0 If a is smaller than b. * @retval >0 If a is greater than b. */ int dpkg_version_compare(const struct dpkg_version *a, const struct dpkg_version *b) { int r; if (a->epoch > b->epoch) return 1; if (a->epoch < b->epoch) return -1; r = verrevcmp(a->version, b->version); if (r) return r; return verrevcmp(a->revision, b->revision); }
/* Compare version strings. * * @s1 first string to compare * @s2 second string to compare * * @return an integer less than, equal to, or greater than zero, if @s1 is <, == or > than @s2. */ int filevercmp (const char *s1, const char *s2) { const char *s1_pos, *s2_pos; const char *s1_suffix, *s2_suffix; size_t s1_len, s2_len; int simple_cmp, result; /* easy comparison to see if strings are identical */ simple_cmp = strcmp (s1, s2); if (simple_cmp == 0) return 0; /* special handle for "", "." and ".." */ if (*s1 == '\0') return -1; if (*s2 == '\0') return 1; if (DIR_IS_DOT (s1)) return -1; if (DIR_IS_DOT (s2)) return 1; if (DIR_IS_DOTDOT (s1)) return -1; if (DIR_IS_DOTDOT (s2)) return 1; /* special handle for other hidden files */ if (*s1 == '.' && *s2 != '.') return -1; if (*s1 != '.' && *s2 == '.') return 1; if (*s1 == '.' && *s2 == '.') { s1++; s2++; } /* "cut" file suffixes */ s1_pos = s1; s2_pos = s2; s1_suffix = match_suffix (&s1_pos); s2_suffix = match_suffix (&s2_pos); s1_len = (s1_suffix != NULL ? s1_suffix : s1_pos) - s1; s2_len = (s2_suffix != NULL ? s2_suffix : s2_pos) - s2; /* restore file suffixes if strings are identical after "cut" */ if ((s1_suffix != NULL || s2_suffix != NULL) && (s1_len == s2_len) && strncmp (s1, s2, s1_len) == 0) { s1_len = s1_pos - s1; s2_len = s2_pos - s2; } result = verrevcmp (s1, s1_len, s2, s2_len); return result == 0 ? simple_cmp : result; }
int OPackageManager::compareVersions( const QString &ver1, const QString &ver2 ) { // TODO - should this be in OIpkg??? int epoch1, epoch2; QString version1, revision1; QString version2, revision2; parseVersion( ver1, &epoch1, &version1, &revision1 ); parseVersion( ver2, &epoch2, &version2, &revision2 ); if ( epoch1 > epoch2 ) return 1; else if ( epoch1 < epoch2 ) return -1; int r = verrevcmp( version1.latin1(), version2.latin1() ); if (r) return r; r = verrevcmp( revision1.latin1(), revision2.latin1() ); return r; }
static gint cmp_vers(gconstpointer a, gconstpointer b) { ASSERT_TYPE((Version *)a, T_VERSION); ASSERT_TYPE((Version *)b, T_VERSION); return -verrevcmp(((Version *)a)->version, ((Version *)b)->version); }