1 #define _POSIX_C_SOURCE 200809L
10 #define DMARK fprintf(stderr, "mark %s %s:%d\n", __FILE__, __func__, __LINE__)
12 int zpm_parse_version(const char *pstr, struct zpm_version_info *info) {
28 /* skip leading whitespace */
29 while (isspace(pstr[cur])) {
33 /* get the name, if any */
34 if (isalpha(pstr[cur])) {
35 info->name = pstr + cur;
36 for (ch = pstr[cur]; ch; ch = pstr[++cur]) {
38 if (isdigit(pstr[cur+1])) {
49 while (pstr[cur] == '-') {
53 /* should be pointing at a digit. if not, we're done */
54 if (isdigit(pstr[cur])) {
55 info->version = pstr + cur;
56 for (ch = pstr[cur]; ch; ch = pstr[++cur]) {
67 while (pstr[cur] == '-') {
71 if (isdigit(pstr[cur])) {
72 info->relstr = pstr + cur;
73 while (isdigit(pstr[cur++])) {
79 info->release = atoi(info->relstr);
82 return info->namelen || info->verlen || info->rellen;
85 int zpm_parse_package(char *pstr, char *name, char *ver, int *rel) {
93 /* string - ver - rel */
94 /* rel is all digits */
96 * ^(.+)-([0-9][^-]*)-([\d+])$
99 * The main problem in parsing is that the package name itself
100 * can contain a '-', so you can't just split on '-'
101 * Also, the version can be just digits.
104 /* everything up to the first '-' is in the name */
106 if (*pstr == '\'' || !isgraph(*pstr)) {
109 if (*pstr == '-' && isdigit(*(pstr+1))) {
122 while (*pstr && *pstr != '-') {
123 if (*pstr == '\'' || !isgraph(*pstr)) {
136 /* TODO use strtol */
142 return havename + havever + haverel;