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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/* Nanar <nanardon@mandrake.org>
* $Id$
*/
#include <string.h>
#define RPMCONSTANT_INTERNAL
#include "rpmconstant.h"
rpmconst rpmconstNew()
{
rpmconst c = NULL;
c = xcalloc(1, sizeof(*c));
c->list = NULL;
c->constant = NULL;
return c;
}
rpmconst rpmconstFree(rpmconst c)
{
free(c);
return c = NULL;
}
void rpmconstInitC(rpmconst c)
{
c->constant = NULL;
}
int rpmconstNextC(rpmconst c)
{
if (c->list == NULL)
return 0;
c->constant = c->constant == NULL ?
rpmConstantListC(c->list) :
rpmConstantNext(c->constant);
return c->constant == NULL ? 0 : 1;
}
void rpmconstInitL(rpmconst c)
{
c->list = NULL;
c->constant = NULL;
}
int rpmconstNextL(rpmconst c)
{
c->list = c->list == NULL ?
(void *) rpmconstanttype :
rpmConstantListNext(c->list);
c->constant = NULL;
return c->list == NULL ? 0 : 1;
}
const char * rpmconstContext(rpmconst c)
{
return rpmConstantListContext(c->list);
}
const char * rpmconstPrefix(rpmconst c)
{
return rpmConstantListPrefix(c->list);
}
const char * rpmconstName(rpmconst c, int stripprefix)
{
char * name;
int len;
name = rpmConstantName(c->constant);
if (stripprefix && name && rpmConstantListPrefix(c->list)) {
len = strlen(rpmConstantListPrefix(c->list));
name += len < strlen(name) ? len : 0;
}
return name;
}
int rpmconstValue(rpmconst c)
{
return rpmConstantValue(c->constant);
}
int rpmconstInitToContext(rpmconst c, const char * context)
{
char * lccontext = strdup(context);
char * ptr;
int rc = 0;
for (ptr = lccontext; *ptr != 0; ptr++)
*ptr = tolower(*ptr);
if (!context) return 0; /* programmer error */
rpmconstInitL(c);
while (rpmconstNextL(c)) {
if (!strcmp(lccontext, rpmconstContext(c))) {
rc = 1;
break;
}
}
free(lccontext);
return rc; /* not found */
}
int rpmconstNameMatch(rpmconst c, const char * name, int prefixed)
{
char * uc;
int rc = 0;
char * ucname = strdup(name);
for (uc = ucname; *uc != 0; uc++)
*uc = toupper(*uc);
if (!prefixed) prefixed = ALLCASE_PREFIX;
if (prefixed & WITH_PREFIX)
if (strcmp(ucname, rpmconstName(c, PREFIXED_YES)) == 0)
rc = 1;
if (!rc && (prefixed & WITHOUT_PREFIX))
if (strcmp(ucname, rpmconstName(c, PREFIXED_NO)) == 0)
rc = 1;
free(ucname);
return rc;
}
int rpmconstFindValue(rpmconst c, const int val)
{
rpmconstInitC(c);
while (rpmconstNextC(c)) {
if (val == rpmconstValue(c))
return 1;
}
return 0;
}
int rpmconstFindMask(rpmconst c, const int val)
{
rpmconstInitC(c);
while (rpmconstNextC(c)) {
if (!rpmconstValue(c))
continue;
if (rpmconstValue(c) & val)
return 1;
}
return 0;
}
int rpmconstFindName(rpmconst c, const char * name, int prefixed)
{
rpmconstInitC(c);
while (rpmconstNextC(c)) {
if (rpmconstNameMatch(c, name, prefixed))
return 1;
}
return 0;
}
int rpmconstantFindValue(char * context, const int val, const char **name, int prefixed)
{
int rc = 0;
rpmconst c = rpmconstNew();
if (rpmconstInitToContext(c, context))
if (rpmconstFindValue(c, val)) {
*name = rpmconstName(c, prefixed);
rc = 1;
}
c = rpmconstFree(c);
return rc;
}
int rpmconstantFindMask(char * context, const int val, const char **name, int prefixed)
{
int rc = 0;
rpmconst c = rpmconstNew();
if (rpmconstInitToContext(c, context))
if (rpmconstFindMask(c, val)) {
*name = rpmconstName(c, prefixed);
rc = rpmconstValue(c);
}
c = rpmconstFree(c);
return rc;
}
int rpmconstantFindName(char * context, const char * name, int *val, int prefixed)
{
int rc = 0;
rpmconst c = rpmconstNew();
if (rpmconstInitToContext(c, context)) {
if (rpmconstFindName(c, name, prefixed)) {
*val |= rpmconstValue(c);
rc = 1;
}
}
c = rpmconstFree(c);
return rc;
}
|