rpm-build/rpmdb/tagname.c

67 lines
1.4 KiB
C
Raw Normal View History

2002-03-25 23:16:26 +03:00
/**
2005-10-15 18:57:00 +04:00
* \file rpmdb/tagname.c
2002-03-25 23:16:26 +03:00
*/
#include "system.h"
#include "rpmlib.h"
2002-03-25 23:16:26 +03:00
#include "debug.h"
const char * tagName(int tag)
2002-03-25 23:16:26 +03:00
{
int i;
static char nameBuf[128]; /* XXX yuk */
char *s;
switch (tag) {
case RPMDBI_PACKAGES:
strcpy(nameBuf, "Packages");
2005-10-15 18:57:00 +04:00
break;
2002-03-25 23:16:26 +03:00
case RPMDBI_ADDED:
strcpy(nameBuf, "Added");
2005-10-15 18:57:00 +04:00
break;
2002-03-25 23:16:26 +03:00
case RPMDBI_REMOVED:
strcpy(nameBuf, "Removed");
2005-10-15 18:57:00 +04:00
break;
2002-03-25 23:16:26 +03:00
case RPMDBI_AVAILABLE:
strcpy(nameBuf, "Available");
2005-10-15 18:57:00 +04:00
break;
default:
strcpy(nameBuf, "(unknown)");
/*@-boundswrite@*/
for (i = 0; i < rpmTagTableSize; i++) {
if (tag != rpmTagTable[i].val)
continue;
nameBuf[0] = nameBuf[1] = '\0';
if (rpmTagTable[i].name != NULL) /* XXX programmer error. */
strcpy(nameBuf, rpmTagTable[i].name + (sizeof("RPMTAG_")-1));
for (s = nameBuf+1; *s != '\0'; s++)
*s = xtolower(*s);
/*@loopbreak@*/ break;
}
/*@=boundswrite@*/
2002-03-25 23:16:26 +03:00
break;
}
return nameBuf;
}
int tagValue(const char * tagstr)
{
const struct headerTagTableEntry_s *t;
2005-10-15 18:57:00 +04:00
if (!xstrcasecmp(tagstr, "Packages"))
2002-03-25 23:16:26 +03:00
return RPMDBI_PACKAGES;
2005-10-15 18:57:00 +04:00
if (!xstrcasecmp(tagstr, "Added"))
2002-03-25 23:16:26 +03:00
return RPMDBI_ADDED;
2005-10-15 18:57:00 +04:00
if (!xstrcasecmp(tagstr, "Removed"))
2002-03-25 23:16:26 +03:00
return RPMDBI_REMOVED;
2005-10-15 18:57:00 +04:00
if (!xstrcasecmp(tagstr, "Available"))
2002-03-25 23:16:26 +03:00
return RPMDBI_AVAILABLE;
for (t = rpmTagTable; t->name != NULL; t++) {
2005-10-15 18:57:00 +04:00
if (!xstrcasecmp(t->name + (sizeof("RPMTAG_")-1), tagstr))
2002-03-25 23:16:26 +03:00
return t->val;
}
return -1;
}