]>
Commit | Line | Data |
---|---|---|
c0668f36 MM |
1 | /* |
2 | * BIRD -- Set/Community-list Operations | |
3 | * | |
4 | * (c) 2000 Martin Mares <mj@ucw.cz> | |
5 | * (c) 2000 Pavel Machek <pavel@ucw.cz> | |
6 | * | |
7 | * Can be freely distributed and used under the terms of the GNU GPL. | |
8 | */ | |
9 | ||
10 | #include "nest/bird.h" | |
11 | #include "nest/route.h" | |
c6add07f | 12 | #include "nest/attrs.h" |
c0668f36 | 13 | #include "lib/resource.h" |
c6add07f MM |
14 | #include "lib/string.h" |
15 | ||
16 | void | |
aebe06b4 | 17 | int_set_format(struct adata *set, int way, byte *buf, unsigned int size) |
c6add07f MM |
18 | { |
19 | u32 *z = (u32 *) set->data; | |
20 | int l = set->length / 4; | |
21 | int sp = 1; | |
22 | byte *end = buf + size - 16; | |
23 | ||
24 | while (l--) | |
25 | { | |
700bbe60 MM |
26 | if (!sp) |
27 | *buf++ = ' '; | |
c6add07f MM |
28 | if (buf > end) |
29 | { | |
30 | strcpy(buf, "..."); | |
31 | return; | |
32 | } | |
aebe06b4 OZ |
33 | |
34 | if (way) | |
35 | buf += bsprintf(buf, "(%d,%d)", *z >> 16, *z & 0xffff); | |
36 | else | |
2f6483cd | 37 | buf += bsprintf(buf, "%R", *z); |
aebe06b4 | 38 | |
c6add07f | 39 | z++; |
700bbe60 | 40 | sp = 0; |
c6add07f MM |
41 | } |
42 | *buf = 0; | |
43 | } | |
9c400ec9 PM |
44 | |
45 | struct adata * | |
46 | int_set_add(struct linpool *pool, struct adata *list, u32 val) | |
47 | { | |
4847a894 OZ |
48 | int len = list ? list->length : 0; |
49 | struct adata *res = lp_alloc(pool, len + sizeof(struct adata) + 4); | |
50 | res->length = len + 4; | |
9c400ec9 | 51 | * (u32 *) res->data = val; |
4847a894 OZ |
52 | if (list) |
53 | memcpy((char *) res->data + 4, list->data, list->length); | |
9c400ec9 PM |
54 | return res; |
55 | } | |
56 | ||
57 | int | |
58 | int_set_contains(struct adata *list, u32 val) | |
59 | { | |
700bbe60 MM |
60 | u32 *l = (u32 *) list->data; |
61 | unsigned int i; | |
9c400ec9 PM |
62 | for (i=0; i<list->length/4; i++) |
63 | if (*l++ == val) | |
64 | return 1; | |
65 | return 0; | |
66 | } | |
67 | ||
68 | struct adata * | |
69 | int_set_del(struct linpool *pool, struct adata *list, u32 val) | |
70 | { | |
71 | struct adata *res; | |
72 | u32 *l, *k; | |
700bbe60 | 73 | unsigned int i; |
9c400ec9 PM |
74 | |
75 | if (!int_set_contains(list, val)) | |
76 | return list; | |
77 | ||
78 | res = lp_alloc(pool, list->length + sizeof(struct adata) - 4); | |
79 | res->length = list->length-4; | |
80 | ||
700bbe60 MM |
81 | l = (u32 *) list->data; |
82 | k = (u32 *) res->data; | |
9c400ec9 PM |
83 | for (i=0; i<list->length/4; i++) |
84 | if (l[i] != val) | |
85 | *k++ = l[i]; | |
86 | ||
87 | return res; | |
88 | } |