~ubuntu-branches/ubuntu/raring/reprepro/raring

« back to all changes in this revision

Viewing changes to atoms.c

  • Committer: Bazaar Package Importer
  • Author(s): Bernhard R. Link
  • Date: 2011-05-05 16:34:23 UTC
  • mfrom: (21.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20110505163423-x49kbdijyoubai4x
Tags: 4.6.0-1
* new release
- general cleanup
- new FilterSrcList
* increase Standards-Version, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
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"
 
35
};
34
36
const char **atomtypes = (const char **)types;
35
37
 
36
38
/* trivial implementation for now, perhaps make it more complicated later */
44
46
        /* add a 0th entry to all, so 0 means uninitialized */
45
47
 
46
48
        r = strlist_add_dup(&architectures, "!!NONE!!");
47
 
        if( RET_WAS_ERROR(r) )
 
49
        if (RET_WAS_ERROR(r))
48
50
                return r;
49
51
        r = strlist_add_dup(&architectures, "source");
50
 
        if( RET_WAS_ERROR(r) )
 
52
        if (RET_WAS_ERROR(r))
51
53
                return r;
52
54
        r = strlist_add_dup(&architectures, "all");
53
 
        if( RET_WAS_ERROR(r) )
 
55
        if (RET_WAS_ERROR(r))
54
56
                return r;
55
57
        r = strlist_add_dup(&components, "!!NONE!!");
56
 
        if( RET_WAS_ERROR(r) )
 
58
        if (RET_WAS_ERROR(r))
57
59
                return 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
        if (RET_WAS_ERROR(r))
61
63
                return 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;
69
71
        }
70
72
        return RET_OK;
75
77
        int i;
76
78
 
77
79
        i = strlist_ofs(&architectures, value);
78
 
        if( i >= 0 ) {
 
80
        if (i >= 0) {
79
81
                *atom_p = (architecture_t)i;
80
82
                return RET_OK;
81
83
        }
82
84
        i = architectures.count;
83
85
        r = strlist_add_dup(&architectures, value);
84
86
        atoms_architectures = (const char**)architectures.values;
85
 
        if( RET_IS_OK(r) ) {
 
87
        if (RET_IS_OK(r)) {
86
88
                *atom_p = (architecture_t)i;
87
89
                return RET_OK;
88
90
        } else
93
95
        int i;
94
96
 
95
97
        i = strlist_ofs(&components, value);
96
 
        if( i >= 0 ) {
 
98
        if (i >= 0) {
97
99
                *atom_p = (component_t)i;
98
100
                return RET_OK;
99
101
        }
100
102
        i = components.count;
101
103
        r = strlist_add_dup(&components, value);
102
104
        atoms_components = (const char**)components.values;
103
 
        if( RET_IS_OK(r) ) {
 
105
        if (RET_IS_OK(r)) {
104
106
                *atom_p = (component_t)i;
105
107
                return RET_OK;
106
108
        } else
109
111
 
110
112
architecture_t architecture_find(const char *value) {
111
113
        int i = strlist_ofs(&architectures, value);
112
 
        if( i < 0 )
 
114
        if (i < 0)
113
115
                return atom_unknown;
114
116
        else
115
117
                return (architecture_t)i;
118
120
architecture_t architecture_find_l(const char *value, size_t l) {
119
121
        architecture_t a;
120
122
 
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);
124
126
 
125
 
                if( len == l && memcmp(name, value, len) == 0 )
 
127
                if (len == l && memcmp(name, value, len) == 0)
126
128
                        return a;
127
129
        }
128
130
        return atom_unknown;
132
134
component_t component_find_l(const char *value, size_t l) {
133
135
        component_t a;
134
136
 
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);
138
140
 
139
 
                if( len == l && memcmp(name, value, len) == 0 )
 
141
                if (len == l && memcmp(name, value, len) == 0)
140
142
                        return a;
141
143
        }
142
144
        return atom_unknown;
144
146
 
145
147
component_t component_find(const char *value) {
146
148
        int i = strlist_ofs(&components, value);
147
 
        if( i < 0 )
 
149
        if (i < 0)
148
150
                return atom_unknown;
149
151
        else
150
152
                return (architecture_t)i;
151
153
}
152
154
 
153
155
packagetype_t packagetype_find(const char *value) {
154
 
        if( strcmp(value, "dsc") == 0 )
 
156
        if (strcmp(value, "dsc") == 0)
155
157
                return pt_dsc;
156
 
        else if( strcmp(value, "deb") == 0 )
 
158
        else if (strcmp(value, "deb") == 0)
157
159
                return pt_deb;
158
 
        else if( strcmp(value, "udeb") == 0 )
 
160
        else if (strcmp(value, "udeb") == 0)
159
161
                return pt_udeb;
160
162
        else
161
163
                return atom_unknown;
162
164
}
163
165
 
164
166
packagetype_t packagetype_find_l(const char *value, size_t len) {
165
 
        if( len == 3 ) {
166
 
                if( strncmp(value, "dsc", 3) == 0 )
 
167
        if (len == 3) {
 
168
                if (strncmp(value, "dsc", 3) == 0)
167
169
                        return pt_dsc;
168
 
                else if( strncmp(value, "deb",3) == 0 )
 
170
                else if (strncmp(value, "deb", 3) == 0)
169
171
                        return pt_deb;
170
 
        } else if( len == 4 && strncmp(value, "udeb",4) == 0 )
 
172
        } else if (len == 4 && strncmp(value, "udeb", 4) == 0)
171
173
                return pt_udeb;
172
174
        return atom_unknown;
173
175
}
175
177
static inline command_t command_find(const char *value) {
176
178
        command_t c;
177
179
 
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)
180
182
                        return c;
181
183
        }
182
184
        return atom_unknown;
183
185
}
184
186
 
185
187
atom_t atom_find(enum atom_type type, const char *value) {
186
 
        switch( type ) {
 
188
        switch (type) {
187
189
                case at_packagetype:
188
190
                        return packagetype_find(value);
189
191
                case at_architecture:
198
200
}
199
201
 
200
202
retvalue atom_intern(enum atom_type type, const char *value, atom_t *atom_p) {
201
 
        assert( type == at_architecture || type == at_component );
202
 
        switch( type ) {
 
203
        assert (type == at_architecture || type == at_component);
 
204
        switch (type) {
203
205
                case at_architecture:
204
206
                        return architecture_intern(value, atom_p);
205
207
                case at_component:
215
217
}
216
218
 
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);
221
223
        }
222
224
        /* reset atoms but not size, so reuse can be catched */
228
230
        int i;
229
231
        atom_t *n;
230
232
 
231
 
        assert( atom_defined(atom) );
 
233
        assert (atom_defined(atom));
232
234
 
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;
236
238
        }
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;
242
244
                list->atoms = n;
248
250
retvalue atomlist_add(struct atomlist *list, atom_t atom) {
249
251
        atom_t *n;
250
252
 
251
 
        assert( atom_defined(atom) );
 
253
        assert (atom_defined(atom));
252
254
 
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;
258
260
                list->atoms = n;
273
275
bool atomlist_hasexcept(const struct atomlist *list, atom_t atom) {
274
276
        int i;
275
277
 
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)
278
280
                        return true;
279
281
        }
280
282
        return false;
283
285
bool atomlist_in(const struct atomlist *list, atom_t atom) {
284
286
        int i;
285
287
 
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)
288
290
                        return true;
289
291
        }
290
292
        return false;
292
294
int atomlist_ofs(const struct atomlist *list, atom_t atom) {
293
295
        int i;
294
296
 
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)
297
299
                        return i;
298
300
        }
299
301
        return -1;
302
304
bool atomlist_subset(const struct atomlist *list, const struct atomlist *subset, atom_t *missing) {
303
305
        int i, j;
304
306
 
305
 
        for( j = 0 ; j < subset->count ; j++ ) {
 
307
        for (j = 0 ; j < subset->count ; j++) {
306
308
                atom_t atom = subset->atoms[j];
307
309
 
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)
310
312
                                break;
311
313
                }
312
 
                if( i >= list->count ) {
313
 
                        if( missing != NULL )
 
314
                if (i >= list->count) {
 
315
                        if (missing != NULL)
314
316
                                *missing = atom;
315
317
                        return false;
316
318
                }
327
329
        assert(list != NULL);
328
330
        assert(file != NULL);
329
331
 
330
 
        switch( type ) {
 
332
        switch (type) {
331
333
                case at_architecture:
332
334
                        atoms = atoms_architectures;
333
335
                        break;
346
348
        c = list->count;
347
349
        p = list->atoms;
348
350
        result = RET_OK;
349
 
        while( c > 0 ) {
350
 
                if( fputs(atoms[*(p++)], file) == EOF )
 
351
        while (c > 0) {
 
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;
354
356
        }
355
357
        return result;
366
368
        atom_t a;
367
369
 
368
370
        atomlist_init(&l);
369
 
        while( *string != '\0' ) {
 
371
        while (*string != '\0') {
370
372
                e = strchr(string, '|');
371
 
                if( e == NULL )
 
373
                if (e == NULL)
372
374
                        e = strchr(string, '\0');
373
375
                else
374
376
                        *(e++) = '\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;
380
382
                }
381
383
                r = atomlist_add(&l, a);
382
 
                if( RET_WAS_ERROR(r) ) {
 
384
                if (RET_WAS_ERROR(r)) {
383
385
                        atomlist_done(&l);
384
386
                        return r;
385
387
                }