Introduce parseEVRD()

It's similar to parseEVR() but also returns disttag.
This commit is contained in:
Vladimir D. Seleznev 2018-12-28 00:43:13 +03:00 committed by Dmitry V. Levin
parent fa25b864cd
commit 9618b8946f
2 changed files with 32 additions and 16 deletions

View File

@ -1488,7 +1488,9 @@ rpmEVRcmp(const char * const aE, const char * const aV, const char * const aR,
* @retval *ep pointer to epoch
* @retval *vp pointer to version
* @retval *rp pointer to release
* @retval *dp pointer to disttag
*/
void parseEVRD(char * evr, const char ** ep, const char ** vp, const char ** rp, const char ** dp);
void parseEVR(char * evr,
/*@exposed@*/ /*@out@*/ const char ** ep,
/*@exposed@*/ /*@out@*/ const char ** vp,

View File

@ -110,46 +110,60 @@ int rpmvercmp(const char * a, const char * b)
/* Moved from depends.c, because we use it in other places, too. */
/**
* Split EVR into epoch, version, and release components.
* @param evr [epoch:]version[-release] string
* Split EVRD into epoch, version, release and disttag components.
* @param evrd [epoch:]version[-release[:disttag]] string
* @retval *ep pointer to epoch
* @retval *vp pointer to version
* @retval *rp pointer to release
* @retval *dp pointer to disttag
*/
void parseEVR(char * evr,
/*@exposed@*/ /*@out@*/ const char ** ep,
/*@exposed@*/ /*@out@*/ const char ** vp,
/*@exposed@*/ /*@out@*/ const char ** rp)
/*@modifies *ep, *vp, *rp @*/
void parseEVRD(char * evrd,
const char ** ep,
const char ** vp,
const char ** rp,
const char ** dp)
{
const char *epoch;
const char *version; /* assume only version is present */
const char *release;
const char *epoch = NULL;
const char *version = NULL; /* assume only version is present */
const char *release = NULL;
const char *disttag = NULL;
char *s, *se;
s = evr;
s = evrd;
while (*s && xisdigit(*s)) s++; /* s points to epoch terminator */
se = strrchr(s, '-'); /* se points to version terminator */
if (*s == ':') {
epoch = evr;
epoch = evrd;
*s++ = '\0';
version = s;
if (*epoch == '\0') epoch = "0";
} else {
epoch = NULL; /* XXX disable epoch compare if missing */
version = evr;
version = evrd;
}
if (se) {
*se++ = '\0';
release = se;
} else {
release = NULL;
se = strchr(se, ':');
if (se) {
*se++ = '\0';
disttag = se;
}
}
if (ep) *ep = epoch;
if (vp) *vp = version;
if (rp) *rp = release;
if (dp) *dp = disttag;
}
/* compat function */
void parseEVR(char *evr,
const char ** ep,
const char ** vp,
const char ** rp)
{
parseEVRD(evr, ep, vp, rp, NULL);
}
/* Compare {A,B} [epoch:]version[-release] */