dependency.c (1948B)
1 #include <alpm.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <assert.h> 5 6 #include "dependency.h" 7 8 betaur_dependency_t* betaur_dependency_create(size_t depstring_len, char* depstring) { 9 betaur_dependency_t* bdep = (betaur_dependency_t *) malloc(sizeof(betaur_dependency_t)); 10 char* pos; 11 bdep->depstring = depstring; 12 bdep->name = depstring; 13 bdep->mod = BETAUR_ANY; 14 assert(bdep != NULL); 15 if (pos = strstr(depstring, "<=")) { 16 17 bdep->mod = BETAUR_LE; 18 bdep->name_len = (size_t) (pos - depstring); 19 bdep->version = pos + 2; 20 bdep->version_len = (size_t) depstring_len - bdep->name_len - 2; 21 } else if (pos = strstr(depstring, ">=")) { 22 bdep->mod = BETAUR_GE; 23 bdep->name_len = (size_t) (pos - depstring); 24 bdep->version = pos + 2; 25 bdep->version_len = (size_t) depstring_len - bdep->name_len - 2; 26 } else { 27 for (pos = depstring; pos < (depstring + depstring_len); pos++) { 28 switch (*pos) { 29 case '<': 30 bdep->mod = BETAUR_LT; 31 break; 32 case '>': 33 bdep->mod = BETAUR_GT; 34 break; 35 case '=': 36 bdep->mod = BETAUR_EQ; 37 break; 38 } 39 } 40 if (bdep->mod != BETAUR_ANY) { 41 bdep->name_len = (size_t) (pos - depstring); 42 bdep->version = pos + 1; 43 bdep->version_len = (size_t) depstring_len - bdep->name_len - 1; 44 } else { 45 bdep->name = depstring; 46 } 47 } 48 49 return bdep; 50 } 51 52 53 bool betaur_satisfied_by_version(betaur_dependency_t* bdep, const char* version) { 54 // FIXME we may need to make a copy here 55 // This will most probably crash when reading input from files 56 int vercmp = alpm_pkg_vercmp(version, bdep->version); 57 // TODO can't we just return vercmp??? hmmm... 58 switch(bdep->mod) { 59 case BETAUR_EQ: 60 return vercmp == 0; 61 case BETAUR_GE: 62 return vercmp >= 0; 63 case BETAUR_GT: 64 return vercmp > 0; 65 case BETAUR_LE: 66 return vercmp <= 0; 67 case BETAUR_LT: 68 return vercmp < 0; 69 default: 70 break; 71 } 72 return false; 73 } 74 75 bool betaur_satisfied_by(betaur_package_t bpack) { 76 return false; 77 }