30
30
const char **atoms_packagetypes = (const char **)&packagetypes;
31
31
const char **atoms_commands;
32
32
static int command_count;
33
static const char * const types[4] = {"architecture", "component", "packagetype", "command"};
33
static const char * const types[4] = {
34
"architecture", "component", "packagetype", "command"
34
36
const char **atomtypes = (const char **)types;
36
38
/* trivial implementation for now, perhaps make it more complicated later */
44
46
/* add a 0th entry to all, so 0 means uninitialized */
46
48
r = strlist_add_dup(&architectures, "!!NONE!!");
47
if( RET_WAS_ERROR(r) )
49
51
r = strlist_add_dup(&architectures, "source");
50
if( RET_WAS_ERROR(r) )
52
54
r = strlist_add_dup(&architectures, "all");
53
if( RET_WAS_ERROR(r) )
55
57
r = strlist_add_dup(&components, "!!NONE!!");
56
if( RET_WAS_ERROR(r) )
58
60
/* a fallback component to put things without a component in */
59
61
r = strlist_add_dup(&components, "strange");
60
if( RET_WAS_ERROR(r) )
62
64
atoms_components = (const char**)components.values;
63
65
atoms_architectures = (const char**)architectures.values;
64
66
command_count = count;
65
if( command_count > 0 ) {
66
atoms_commands = calloc(command_count + 1, sizeof(const char*));
67
if( FAILEDTOALLOC(atoms_commands) )
67
if (command_count > 0) {
68
atoms_commands = nzNEW(command_count + 1, const char*);
69
if (FAILEDTOALLOC(atoms_commands))
68
70
return RET_ERROR_OOM;
77
79
i = strlist_ofs(&architectures, value);
79
81
*atom_p = (architecture_t)i;
82
84
i = architectures.count;
83
85
r = strlist_add_dup(&architectures, value);
84
86
atoms_architectures = (const char**)architectures.values;
86
88
*atom_p = (architecture_t)i;
95
97
i = strlist_ofs(&components, value);
97
99
*atom_p = (component_t)i;
100
102
i = components.count;
101
103
r = strlist_add_dup(&components, value);
102
104
atoms_components = (const char**)components.values;
104
106
*atom_p = (component_t)i;
118
120
architecture_t architecture_find_l(const char *value, size_t l) {
119
121
architecture_t a;
121
for( a = architectures.count - 1 ; a > 0 ; a-- ) {
123
for (a = architectures.count - 1 ; a > 0 ; a--) {
122
124
const char *name = atoms_architectures[a];
123
125
size_t len = strlen(name);
125
if( len == l && memcmp(name, value, len) == 0 )
127
if (len == l && memcmp(name, value, len) == 0)
128
130
return atom_unknown;
132
134
component_t component_find_l(const char *value, size_t l) {
135
for( a = components.count - 1 ; a > 0 ; a-- ) {
137
for (a = components.count - 1 ; a > 0 ; a--) {
136
138
const char *name = atoms_components[a];
137
139
size_t len = strlen(name);
139
if( len == l && memcmp(name, value, len) == 0 )
141
if (len == l && memcmp(name, value, len) == 0)
142
144
return atom_unknown;
145
147
component_t component_find(const char *value) {
146
148
int i = strlist_ofs(&components, value);
148
150
return atom_unknown;
150
152
return (architecture_t)i;
153
155
packagetype_t packagetype_find(const char *value) {
154
if( strcmp(value, "dsc") == 0 )
156
if (strcmp(value, "dsc") == 0)
156
else if( strcmp(value, "deb") == 0 )
158
else if (strcmp(value, "deb") == 0)
158
else if( strcmp(value, "udeb") == 0 )
160
else if (strcmp(value, "udeb") == 0)
161
163
return atom_unknown;
164
166
packagetype_t packagetype_find_l(const char *value, size_t len) {
166
if( strncmp(value, "dsc", 3) == 0 )
168
if (strncmp(value, "dsc", 3) == 0)
168
else if( strncmp(value, "deb",3) == 0 )
170
else if (strncmp(value, "deb", 3) == 0)
170
} else if( len == 4 && strncmp(value, "udeb",4) == 0 )
172
} else if (len == 4 && strncmp(value, "udeb", 4) == 0)
172
174
return atom_unknown;
175
177
static inline command_t command_find(const char *value) {
178
for( c = command_count ; c > 0 ; c-- ) {
179
if( strcmp(atoms_commands[c], value) == 0 )
180
for (c = command_count ; c > 0 ; c--) {
181
if (strcmp(atoms_commands[c], value) == 0)
182
184
return atom_unknown;
185
187
atom_t atom_find(enum atom_type type, const char *value) {
187
189
case at_packagetype:
188
190
return packagetype_find(value);
189
191
case at_architecture:
200
202
retvalue atom_intern(enum atom_type type, const char *value, atom_t *atom_p) {
201
assert( type == at_architecture || type == at_component );
203
assert (type == at_architecture || type == at_component);
203
205
case at_architecture:
204
206
return architecture_intern(value, atom_p);
205
207
case at_component:
217
219
void atomlist_done(struct atomlist *list) {
218
if( list->size > 0 ) {
219
assert( list->atoms != 0 );
220
if (list->size > 0) {
221
assert (list->atoms != 0);
220
222
free(list->atoms);
222
224
/* reset atoms but not size, so reuse can be catched */
231
assert( atom_defined(atom) );
233
assert (atom_defined(atom));
233
for( i = 0 ; i < list->count ; i++ ) {
234
if( list->atoms[i] == atom )
235
for (i = 0 ; i < list->count ; i++) {
236
if (list->atoms[i] == atom)
235
237
return RET_NOTHING;
237
if( list->size <= list->count ) {
238
n = realloc(list->atoms, (sizeof(atom_t))*(list->count + 8) );
239
if( FAILEDTOALLOC(n) )
239
if (list->size <= list->count) {
240
n = realloc(list->atoms, (sizeof(atom_t))*(list->count + 8));
241
if (FAILEDTOALLOC(n))
240
242
return RET_ERROR_OOM;
241
243
list->size = list->count + 8;
248
250
retvalue atomlist_add(struct atomlist *list, atom_t atom) {
251
assert( atom_defined(atom) );
253
assert (atom_defined(atom));
253
if( list->size <= list->count ) {
254
n = realloc(list->atoms, (sizeof(atom_t))*(list->count + 8) );
255
if( FAILEDTOALLOC(n) )
255
if (list->size <= list->count) {
256
n = realloc(list->atoms, (sizeof(atom_t))*(list->count + 8));
257
if (FAILEDTOALLOC(n))
256
258
return RET_ERROR_OOM;
257
259
list->size = list->count + 8;
273
275
bool atomlist_hasexcept(const struct atomlist *list, atom_t atom) {
276
for( i = 0 ; i < list->count ; i++ ) {
277
if( list->atoms[i] != atom )
278
for (i = 0 ; i < list->count ; i++) {
279
if (list->atoms[i] != atom)
283
285
bool atomlist_in(const struct atomlist *list, atom_t atom) {
286
for( i = 0 ; i < list->count ; i++ ) {
287
if( list->atoms[i] == atom )
288
for (i = 0 ; i < list->count ; i++) {
289
if (list->atoms[i] == atom)
292
294
int atomlist_ofs(const struct atomlist *list, atom_t atom) {
295
for( i = 0 ; i < list->count ; i++ ) {
296
if( list->atoms[i] == atom )
297
for (i = 0 ; i < list->count ; i++) {
298
if (list->atoms[i] == atom)
302
304
bool atomlist_subset(const struct atomlist *list, const struct atomlist *subset, atom_t *missing) {
305
for( j = 0 ; j < subset->count ; j++ ) {
307
for (j = 0 ; j < subset->count ; j++) {
306
308
atom_t atom = subset->atoms[j];
308
for( i = 0 ; i < list->count ; i++ ) {
309
if( list->atoms[i] == atom )
310
for (i = 0 ; i < list->count ; i++) {
311
if (list->atoms[i] == atom)
312
if( i >= list->count ) {
313
if( missing != NULL )
314
if (i >= list->count) {
350
if( fputs(atoms[*(p++)], file) == EOF )
352
if (fputs(atoms[*(p++)], file) == EOF)
351
353
result = RET_ERROR;
352
if( --c > 0 && fputc(' ', file) == EOF )
354
if (--c > 0 && fputc(' ', file) == EOF)
353
355
result = RET_ERROR;
368
370
atomlist_init(&l);
369
while( *string != '\0' ) {
371
while (*string != '\0') {
370
372
e = strchr(string, '|');
372
374
e = strchr(string, '\0');
375
377
a = atom_find(type, string);
376
if( !atom_defined(a) ) {
378
if (!atom_defined(a)) {
377
379
atomlist_done(&l);
378
380
*missing = string;
379
381
return RET_NOTHING;
381
383
r = atomlist_add(&l, a);
382
if( RET_WAS_ERROR(r) ) {
384
if (RET_WAS_ERROR(r)) {
383
385
atomlist_done(&l);