00001
00005 #include "system.h"
00006
00007 #include <rpmlib.h>
00008 #include "debug.h"
00009
00010
00011
00012 static int tagcmp(const void * a, const void * b)
00013
00014 {
00015 const headerTagTableEntry aptr = a;
00016 const headerTagTableEntry bptr = b;
00017 return (aptr->val - bptr->val);
00018 }
00019
00020 int tagType(int tag)
00021 {
00022 headerTagTableEntry t = memset(alloca(sizeof(*t)), 0, sizeof(*t));
00023 headerTagTableEntry needle;
00024 int tagtype = RPM_NULL_TYPE;
00025
00026 t->val = tag;
00027
00028 needle = bsearch(t, rpmTagTable, rpmTagTableSize, sizeof(*t), tagcmp);
00029
00030 if (needle != NULL)
00031 tagtype = needle->type;
00032 return tagtype;
00033 }
00034
00035 const char *const tagName(int tag)
00036 {
00037 static char nameBuf[128];
00038 char *s;
00039 int i;
00040
00041 switch (tag) {
00042 case RPMDBI_PACKAGES:
00043 strcpy(nameBuf, "Packages");
00044 break;
00045 case RPMDBI_DEPENDS:
00046 strcpy(nameBuf, "Depends");
00047 break;
00048 case RPMDBI_ADDED:
00049 strcpy(nameBuf, "Added");
00050 break;
00051 case RPMDBI_REMOVED:
00052 strcpy(nameBuf, "Removed");
00053 break;
00054 case RPMDBI_AVAILABLE:
00055 strcpy(nameBuf, "Available");
00056 break;
00057 case RPMDBI_HDLIST:
00058 strcpy(nameBuf, "Hdlist");
00059 break;
00060 case RPMDBI_ARGLIST:
00061 strcpy(nameBuf, "Arglist");
00062 break;
00063 case RPMDBI_FTSWALK:
00064 strcpy(nameBuf, "Ftswalk");
00065 break;
00066 default:
00067 strcpy(nameBuf, "(unknown)");
00068
00069 for (i = 0; i < rpmTagTableSize; i++) {
00070 if (tag != rpmTagTable[i].val)
00071 continue;
00072 nameBuf[0] = nameBuf[1] = '\0';
00073 if (rpmTagTable[i].name != NULL)
00074 strcpy(nameBuf, rpmTagTable[i].name + (sizeof("RPMTAG_")-1));
00075 for (s = nameBuf+1; *s != '\0'; s++)
00076 *s = xtolower(*s);
00077 break;
00078 }
00079
00080 break;
00081 }
00082 return nameBuf;
00083 }
00084
00085 int tagValue(const char * tagstr)
00086 {
00087 const struct headerTagTableEntry_s *t;
00088
00089 if (!xstrcasecmp(tagstr, "Packages"))
00090 return RPMDBI_PACKAGES;
00091 if (!xstrcasecmp(tagstr, "Depends"))
00092 return RPMDBI_DEPENDS;
00093 if (!xstrcasecmp(tagstr, "Added"))
00094 return RPMDBI_ADDED;
00095 if (!xstrcasecmp(tagstr, "Removed"))
00096 return RPMDBI_REMOVED;
00097 if (!xstrcasecmp(tagstr, "Available"))
00098 return RPMDBI_AVAILABLE;
00099 if (!xstrcasecmp(tagstr, "Hdlist"))
00100 return RPMDBI_HDLIST;
00101 if (!xstrcasecmp(tagstr, "Arglist"))
00102 return RPMDBI_ARGLIST;
00103 if (!xstrcasecmp(tagstr, "Ftswalk"))
00104 return RPMDBI_FTSWALK;
00105
00106 for (t = rpmTagTable; t->name != NULL; t++) {
00107 if (!xstrcasecmp(t->name + (sizeof("RPMTAG_")-1), tagstr))
00108 return t->val;
00109 }
00110 return -1;
00111 }