# tagName.c

Go to the documentation of this file.

    00001
    00005 #include "system.h"
    00006
    00007 #include <rpmlib.h>
    00008 #include "debug.h"
    00009
    00010 const char *const tagName(int tag)
    00011 {
    00012     int i;
    00013     static char nameBuf[128];   /* XXX yuk */
    00014     char *s;
    00015
    00016     switch (tag) {
    00017     case RPMDBI_PACKAGES:
    00018         strcpy(nameBuf, "Packages");
    00019         return nameBuf;
    00020         /*@notreached@*/ break;
    00021     case RPMDBI_DEPENDS:
    00022         strcpy(nameBuf, "Depends");
    00023         return nameBuf;
    00024         /*@notreached@*/ break;
    00025     case RPMDBI_ADDED:
    00026         strcpy(nameBuf, "Added");
    00027         return nameBuf;
    00028         /*@notreached@*/ break;
    00029     case RPMDBI_REMOVED:
    00030         strcpy(nameBuf, "Removed");
    00031         return nameBuf;
    00032         /*@notreached@*/ break;
    00033     case RPMDBI_AVAILABLE:
    00034         strcpy(nameBuf, "Available");
    00035         return nameBuf;
    00036         /*@notreached@*/ break;
    00037     }
    00038
    00039     strcpy(nameBuf, "(unknown)");
    00040     for (i = 0; i < rpmTagTableSize; i++) {
    00041         if (tag != rpmTagTable[i].val)
    00042             continue;
    00043         nameBuf[0] = nameBuf[1] = '\0';
    00044         if (rpmTagTable[i].name != NULL)        /* XXX programmer error. */
    00045             strcpy(nameBuf, rpmTagTable[i].name + 7);
    00046         for (s = nameBuf+1; *s != '\0'; s++)
    00047             *s = xtolower(*s);
    00048         break;
    00049     }
    00050     return nameBuf;
    00051 }
    00052
    00053 int tagValue(const char * tagstr)
    00054 {
    00055     const struct headerTagTableEntry_s *t;
    00056
    00057     if (!strcmp(tagstr, "Packages"))
    00058         return RPMDBI_PACKAGES;
    00059     if (!strcmp(tagstr, "Depends"))
    00060         return RPMDBI_DEPENDS;
    00061     if (!strcmp(tagstr, "Added"))
    00062         return RPMDBI_ADDED;
    00063     if (!strcmp(tagstr, "Removed"))
    00064         return RPMDBI_REMOVED;
    00065     if (!strcmp(tagstr, "Available"))
    00066         return RPMDBI_AVAILABLE;
    00067
    00068     for (t = rpmTagTable; t->name != NULL; t++) {
    00069         if (!xstrcasecmp(t->name + 7, tagstr))
    00070             return t->val;
    00071     }
    00072     return -1;
    00073 }