2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
12 /* we need FNM_CASEFOLD */
21 #include "poolvendor.h"
25 * const char *vendorsclasses[] = {
26 * "!openSUSE Build Service*",
31 * "Silicon Graphics*",
32 * "Jpackage Project*",
33 * "ATI Technologies Inc.*",
40 /* allows for 32 different vendor classes */
42 Id pool_vendor2mask(Pool *pool, Id vendor)
49 if (vendor == 0 || !pool->vendorclasses)
51 for (i = 0; i < pool->vendormap.count; i += 2)
52 if (pool->vendormap.elements[i] == vendor)
53 return pool->vendormap.elements[i + 1];
54 vstr = pool_id2str(pool, vendor);
57 for (v = pool->vendorclasses; ; v++)
60 if (vs == 0) /* end of block? */
66 break; /* sorry, out of bits */
67 m <<= 1; /* next vendor equivalence class */
69 if (fnmatch(*vs == '!' ? vs + 1 : vs, vstr, FNM_CASEFOLD) == 0)
73 while (v[1]) /* forward to next block */
77 queue_push(&pool->vendormap, vendor);
78 queue_push(&pool->vendormap, mask);
83 pool_setvendorclasses(Pool *pool, const char **vendorclasses)
88 if (pool->vendorclasses)
90 for (v = pool->vendorclasses; v[0] || v[1]; v++)
91 solv_free((void *)*v);
92 pool->vendorclasses = solv_free(pool->vendorclasses);
94 if (!vendorclasses || !vendorclasses[0])
96 for (v = vendorclasses; v[0] || v[1]; v++)
98 pool->vendorclasses = solv_calloc(v - vendorclasses + 2, sizeof(const char *));
99 for (v = vendorclasses, i = 0; v[0] || v[1]; v++, i++)
100 pool->vendorclasses[i] = *v ? solv_strdup(*v) : 0;
101 pool->vendorclasses[i++] = 0;
102 pool->vendorclasses[i] = 0;
103 queue_empty(&pool->vendormap);
107 pool_addvendorclass(Pool *pool, const char **vendorclass)
111 if (!vendorclass || !vendorclass[0])
113 for (j = 1; vendorclass[j]; j++)
116 if (pool->vendorclasses)
118 for (i = 0; pool->vendorclasses[i] || pool->vendorclasses[i + 1]; i++)
123 pool->vendorclasses = solv_realloc2(pool->vendorclasses, i + j + 2, sizeof(const char *));
124 for (j = 0; vendorclass[j]; j++)
125 pool->vendorclasses[i++] = solv_strdup(vendorclass[j]);
126 pool->vendorclasses[i++] = 0;
127 pool->vendorclasses[i] = 0;
128 queue_empty(&pool->vendormap);