On Sat, Aug 20, 2011 at 9:42 PM, Dave Reisner <d@falconindy.com> wrote:
Signed-off-by: Dave Reisner <dreisner@archlinux.org> NACK. This makes diffing with the RPM code a lot tougher. Read the comments at the top of the file- I thought I noted this?
--- lib/libalpm/version.c | 49 ++++++++++++++++++++++++++++++++----------------- 1 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/lib/libalpm/version.c b/lib/libalpm/version.c index bab9f92..f86e0c0 100644 --- a/lib/libalpm/version.c +++ b/lib/libalpm/version.c @@ -107,8 +107,12 @@ static int rpmvercmp(const char *a, const char *b)
/* loop through each version segment of str1 and str2 and compare them */ while(*one && *two) { - while(*one && !isalnum((int)*one)) one++; - while(*two && !isalnum((int)*two)) two++; + while(*one && !isalnum((int)*one)) { + one++; + } + while(*two && !isalnum((int)*two)) { + two++; + }
/* If we ran to the end of either, we are finished with the loop */ if(!(*one && *two)) break; @@ -120,12 +124,20 @@ static int rpmvercmp(const char *a, const char *b) /* leave one and two pointing to the start of the alpha or numeric */ /* segment and walk ptr1 and ptr2 to end of segment */ if(isdigit((int)*ptr1)) { - while(*ptr1 && isdigit((int)*ptr1)) ptr1++; - while(*ptr2 && isdigit((int)*ptr2)) ptr2++; + while(*ptr1 && isdigit((int)*ptr1)) { + ptr1++; + } + while(*ptr2 && isdigit((int)*ptr2)) { + ptr2++; + } isnum = 1; } else { - while(*ptr1 && isalpha((int)*ptr1)) ptr1++; - while(*ptr2 && isalpha((int)*ptr2)) ptr2++; + while(*ptr1 && isalpha((int)*ptr1)) { + ptr1++; + } + while(*ptr2 && isalpha((int)*ptr2)) { + ptr2++; + } isnum = 0; }
@@ -138,7 +150,7 @@ static int rpmvercmp(const char *a, const char *b)
/* this cannot happen, as we previously tested to make sure that */ /* the first string has a non-null segment */ - if (one == ptr1) { + if(one == ptr1) { ret = -1; /* arbitrary */ goto cleanup; } @@ -147,26 +159,30 @@ static int rpmvercmp(const char *a, const char *b) /* different types: one numeric, the other alpha (i.e. empty) */ /* numeric segments are always newer than alpha segments */ /* XXX See patch #60884 (and details) from bugzilla #50977. */ - if (two == ptr2) { + if(two == ptr2) { ret = isnum ? 1 : -1; goto cleanup; }
- if (isnum) { + if(isnum) { /* this used to be done by converting the digit segments */ /* to ints using atoi() - it's changed because long */ /* digit segments can overflow an int - this should fix that. */
/* throw away any leading zeros - it's a number, right? */ - while (*one == '0') one++; - while (*two == '0') two++; + while(*one == '0') { + one++; + } + while(*two == '0') { + two++; + }
/* whichever number has more digits wins */ - if (strlen(one) > strlen(two)) { + if(strlen(one) > strlen(two)) { ret = 1; goto cleanup; } - if (strlen(two) > strlen(one)) { + if(strlen(two) > strlen(one)) { ret = -1; goto cleanup; } @@ -177,7 +193,7 @@ static int rpmvercmp(const char *a, const char *b) /* if they are equal because there might be more segments to */ /* compare */ rc = strcmp(one, two); - if (rc) { + if(rc) { ret = rc < 1 ? -1 : 1; goto cleanup; } @@ -193,7 +209,7 @@ static int rpmvercmp(const char *a, const char *b) /* compared identically but the segment separating characters were */ /* different. versions must also be the same length to be equivalent, */ /* otherwise, the shorter version is declared newer. */ - if ((!*one) && (!*two)) { + if((!*one) && (!*two)) { int diff = two_len - one_len; ret = 0; if(diff > 0) { @@ -210,8 +226,7 @@ static int rpmvercmp(const char *a, const char *b) * - if one is an alpha, two is newer. * - otherwise one is newer. * */ - if ( (!*one && !isalpha((int)*two)) - || isalpha((int)*one) ) { + if((!*one && !isalpha((int)*two)) || isalpha((int)*one) ) { ret = -1; } else { ret = 1; -- 1.7.6