summaryrefslogtreecommitdiff
path: root/rpmdb/tagname.c
blob: 4434932436c2bc686edf4ea49b945683eea3a5b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * \file rpmdb/tagname.c
 */

#include "system.h"

#include <rpmlib.h>
#include "debug.h"

const char *const tagName(int tag)
{
    int i;
    static char nameBuf[128];	/* XXX yuk */
    char *s;

    switch (tag) {
    case RPMDBI_PACKAGES:
	strcpy(nameBuf, "Packages");
	return nameBuf;
	/*@notreached@*/ break;
    case RPMDBI_DEPENDS:
	strcpy(nameBuf, "Depends");
	return nameBuf;
	/*@notreached@*/ break;
    case RPMDBI_ADDED:
	strcpy(nameBuf, "Added");
	return nameBuf;
	/*@notreached@*/ break;
    case RPMDBI_REMOVED:
	strcpy(nameBuf, "Removed");
	return nameBuf;
	/*@notreached@*/ break;
    case RPMDBI_AVAILABLE:
	strcpy(nameBuf, "Available");
	return nameBuf;
	/*@notreached@*/ break;
    }

    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 + 7);
	for (s = nameBuf+1; *s != '\0'; s++)
	    *s = xtolower(*s);
	break;
    }
/*@=boundswrite@*/
    return nameBuf;
}

int tagValue(const char * tagstr)
{
    const struct headerTagTableEntry_s *t;

    if (!strcmp(tagstr, "Packages"))
	return RPMDBI_PACKAGES;
    if (!strcmp(tagstr, "Depends"))
	return RPMDBI_DEPENDS;
    if (!strcmp(tagstr, "Added"))
	return RPMDBI_ADDED;
    if (!strcmp(tagstr, "Removed"))
	return RPMDBI_REMOVED;
    if (!strcmp(tagstr, "Available"))
	return RPMDBI_AVAILABLE;

    for (t = rpmTagTable; t->name != NULL; t++) {
	if (!xstrcasecmp(t->name + 7, tagstr))
	    return t->val;
    }
    return -1;
}