X-Git-Url: https://pd.if.org/git/?p=zpackage;a=blobdiff_plain;f=lib%2Fparse.c;h=2451e3f007b332a9b49926313fa75c31c0020f7a;hp=5009c01bff3decc5964459457dcd795d3bb6aed8;hb=b0c5db32f5f53b5d43170756668e0c0387a88f13;hpb=e0214f50fcf9ed0fdcdca444986fc998db5d0dee diff --git a/lib/parse.c b/lib/parse.c index 5009c01..2451e3f 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -7,10 +7,81 @@ #include "zpm.h" -#include "sqlite3.h" - #define DMARK fprintf(stderr, "mark %s %s:%d\n", __FILE__, __func__, __LINE__) +int zpm_parse_version(const char *pstr, struct zpm_version_info *info) { + int cur = 0, ch; + + info->verstr = pstr; + info->name = 0; + info->namelen = 0; + info->version = 0; + info->verlen = 0; + info->release = -1; + info->rellen = 0; + info->relstr = 0; + + if (!pstr) { + return 0; + } + + /* skip leading whitespace */ + while (isspace(pstr[cur])) { + cur++; + } + + /* get the name, if any */ + if (isalpha(pstr[cur])) { + info->name = pstr + cur; + for (ch = pstr[cur]; ch; ch = pstr[++cur]) { + if (ch == '-') { + if (isdigit(pstr[cur+1])) { + break; + } + } + if (!isgraph(ch)) { + break; + } + info->namelen++; + } + } + + while (pstr[cur] == '-') { + cur++; + } + + /* should be pointing at a digit. if not, we're done */ + if (isdigit(pstr[cur])) { + info->version = pstr + cur; + for (ch = pstr[cur]; ch; ch = pstr[++cur]) { + if (ch == '-') { + break; + } + if (!isgraph(ch)) { + break; + } + info->verlen++; + } + } + + while (pstr[cur] == '-') { + cur++; + } + + if (isdigit(pstr[cur])) { + info->relstr = pstr + cur; + while (isdigit(pstr[cur++])) { + info->rellen++; + } + } + + if (info->relstr) { + info->release = atoi(info->relstr); + } + + return info->namelen || info->verlen || info->rellen; +} + int zpm_parse_package(char *pstr, char *name, char *ver, int *rel) { if (name) *name = 0; if (ver) *ver = 0;