+void parse_package(char *pstr, char *name, char *ver, int *rel) {
+ if (name) *name = 0;
+ if (ver) *ver = 0;
+ if (rel) *rel = -1;
+
+ /* string - ver - rel */
+ /* rel is all digits */
+ /* possible forms:
+ * ^(.+)-([0-9][^-]*)-([\d+])$
+ * ^(.+)-([0-9][^-]*)$
+ * ^(.+)$
+ * The main problem in parsing is that the package name itself
+ * can contain a '-', so you can't just split on '-'
+ * Also, the version can be just digits.
+ */
+
+ /* everything up to the first '-' is in the name */
+ while (*pstr) {
+ if (*pstr == '-' && isdigit(*(pstr+1))) {
+ break;
+ }
+ if (name) {
+ *name++ = *pstr;
+ }
+ pstr++;
+ }
+ if (name) *name = 0;
+ if (*pstr == '-') {
+ pstr++;
+ }
+ while (*pstr && *pstr != '-') {
+ if (ver) {
+ *ver++ = *pstr;
+ }
+ pstr++;
+ }
+ if (ver) *ver = 0;
+ if (*pstr == '-') {
+ pstr++;
+ }
+ if (rel && *pstr) {
+ *rel = atoi(pstr);
+ }
+}
+