Changeset 4129


Ignore:
Timestamp:
02/28/08 12:36:53 (5 years ago)
Author:
thomas
Message:

opkg: Update the version comparision to a more recent one from dpkg. This
means it now recognises 0.0-foo > 0.0+foo as it should. Patch from Richard
Purdie <rpurdie rpsys net>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/target/opkg/libopkg/pkg.c

    r4029 r4129  
    10801080} 
    10811081 
    1082 int verrevcmp(const char *val, const char *ref) 
    1083 { 
    1084      int vc, rc; 
    1085      long vl, rl; 
    1086      const char *vp, *rp; 
    1087      const char *vsep, *rsep; 
    1088      
    1089      if (!val) val= ""; 
    1090      if (!ref) ref= ""; 
    1091      for (;;) { 
    1092           vp= val;  while (*vp && !isdigit(*vp)) vp++; 
    1093           rp= ref;  while (*rp && !isdigit(*rp)) rp++; 
    1094           for (;;) { 
    1095                vc= (val == vp) ? 0 : *val++; 
    1096                rc= (ref == rp) ? 0 : *ref++; 
    1097                if (!rc && !vc) break; 
    1098                if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ 
    1099                if (rc && !isalpha(rc)) rc += 256; 
    1100                if (vc != rc) return vc - rc; 
    1101           } 
    1102           val= vp; 
    1103           ref= rp; 
    1104           vl=0;  if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); 
    1105           rl=0;  if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); 
    1106           if (vl != rl) return vl - rl; 
    1107  
    1108           vc = *val; 
    1109           rc = *ref; 
    1110           vsep = strchr(".-", vc); 
    1111           rsep = strchr(".-", rc); 
    1112           if (vsep && !rsep) return -1; 
    1113           if (!vsep && rsep) return +1; 
    1114  
    1115           if (!*val && !*ref) return 0; 
    1116           if (!*val) return -1; 
    1117           if (!*ref) return +1; 
    1118      } 
     1082/* assume ascii; warning: evaluates x multiple times! */ 
     1083#define order(x) ((x) == '~' ? -1 \ 
     1084                : isdigit((x)) ? 0 \ 
     1085                : !(x) ? 0 \ 
     1086                : isalpha((x)) ? (x) \ 
     1087                : (x) + 256) 
     1088 
     1089static int verrevcmp(const char *val, const char *ref) { 
     1090  if (!val) val= ""; 
     1091  if (!ref) ref= ""; 
     1092 
     1093  while (*val || *ref) { 
     1094    int first_diff= 0; 
     1095 
     1096    while ( (*val && !isdigit(*val)) || (*ref && !isdigit(*ref)) ) { 
     1097      int vc= order(*val), rc= order(*ref); 
     1098      if (vc != rc) return vc - rc; 
     1099      val++; ref++; 
     1100    } 
     1101 
     1102    while ( *val == '0' ) val++; 
     1103    while ( *ref == '0' ) ref++; 
     1104    while (isdigit(*val) && isdigit(*ref)) { 
     1105      if (!first_diff) first_diff= *val - *ref; 
     1106      val++; ref++; 
     1107    } 
     1108    if (isdigit(*val)) return 1; 
     1109    if (isdigit(*ref)) return -1; 
     1110    if (first_diff) return first_diff; 
     1111  } 
     1112  return 0; 
    11191113} 
    11201114 
Note: See TracChangeset for help on using the changeset viewer.