diff options
author | Michael Schroeder <mls@suse.de> | 2014-02-12 19:48:24 +0100 |
---|---|---|
committer | Michael Schroeder <mls@suse.de> | 2014-02-12 19:48:24 +0100 |
commit | 4e05e86026adaebd5a01d80fa29bc6fcd7a85596 (patch) | |
tree | 03241846762f835a805fc56e372b7e477c6ac476 | |
parent | 5b07accd422fcdc8c583f3f0b6b4798c408cb441 (diff) | |
download | libsolv-4e05e86026adaebd5a01d80fa29bc6fcd7a85596.tar.gz libsolv-4e05e86026adaebd5a01d80fa29bc6fcd7a85596.tar.bz2 libsolv-4e05e86026adaebd5a01d80fa29bc6fcd7a85596.zip |
refactor testcase_str2dep
- no longer patch the string
- also support REL_AND (&) and REL_COND (IF)
-rw-r--r-- | ext/testcase.c | 61 | ||||
-rw-r--r-- | ext/testcase.h | 2 |
2 files changed, 47 insertions, 16 deletions
diff --git a/ext/testcase.c b/ext/testcase.c index a067aff..a1c8ee6 100644 --- a/ext/testcase.c +++ b/ext/testcase.c @@ -287,21 +287,14 @@ pool_isknownarch(Pool *pool, Id id) return 1; } -Id -testcase_str2dep(Pool *pool, char *s) +static Id +testcase_str2dep_simple(Pool *pool, const char **sp) { - char *n, *a; + const char *s = *sp; + const char *n, *a; Id id, evr; int flags; - if ((n = strchr(s, '|')) != 0) - { - id = testcase_str2dep(pool, n + 1); - *n = 0; - id = pool_rel2id(pool, testcase_str2dep(pool, s), id, REL_OR, 1); - *n = '|'; - return id; - } while (*s == ' ' || *s == '\t') s++; n = s; @@ -311,9 +304,9 @@ testcase_str2dep(Pool *pool, char *s) { while (*s && *s != ')') s++; + continue; } - else - s++; + s++; } if ((a = strchr(n, '.')) != 0 && a + 1 < s && s[-1] != ')') { @@ -334,7 +327,10 @@ testcase_str2dep(Pool *pool, char *s) else id = pool_strn2id(pool, n, s - n, 1); if (!*s) - return id; + { + *sp = s; + return id; + } while (*s == ' ' || *s == '\t') s++; flags = 0; @@ -355,7 +351,10 @@ testcase_str2dep(Pool *pool, char *s) break; } if (!flags) - return id; + { + *sp = s; + return id; + } while (*s == ' ' || *s == '\t') s++; n = s; @@ -372,9 +371,41 @@ testcase_str2dep(Pool *pool, char *s) s++; evr = pool_rel2id(pool, evr, pool_strn2id(pool, n, s - n, 1), REL_COMPAT, 1); } + *sp = s; return pool_rel2id(pool, id, evr, flags, 1); } +static Id +testcase_str2dep_complex(Pool *pool, const char **sp) +{ + const char *s = *sp; + Id id; + id = testcase_str2dep_simple(pool, &s); + if (*s == '|') + { + s++; + id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_OR, 1); + } + else if (*s == '&') + { + s++; + id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_AND, 1); + } + else if (*s == 'I' && s[1] == 'F' && (s[2] == ' ' || s[2] == '\t')) + { + s += 2; + id = pool_rel2id(pool, id, testcase_str2dep_complex(pool, &s), REL_COND, 1); + } + *sp = s; + return id; +} + +Id +testcase_str2dep(Pool *pool, const char *s) +{ + return testcase_str2dep_complex(pool, &s); +} + const char * testcase_repoid2str(Pool *pool, Id repoid) { diff --git a/ext/testcase.h b/ext/testcase.h index 20c7095..4243e4f 100644 --- a/ext/testcase.h +++ b/ext/testcase.h @@ -15,7 +15,7 @@ #define TESTCASE_RESULT_RECOMMENDED (1 << 3) #define TESTCASE_RESULT_UNNEEDED (1 << 4) -extern Id testcase_str2dep(Pool *pool, char *s); +extern Id testcase_str2dep(Pool *pool, const char *s); extern const char *testcase_repoid2str(Pool *pool, Id repoid); extern const char *testcase_solvid2str(Pool *pool, Id p); extern Repo *testcase_str2repo(Pool *pool, const char *str); |