35ffb5007fdfc1619b2766ee72944cf7b30d9097
[platform/upstream/libsolv.git] / src / poolvendor.c
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11
12 /* we need FNM_CASEFOLD */
13 #ifndef _GNU_SOURCE
14 #define _GNU_SOURCE
15 #endif
16
17 #include <fnmatch.h>
18
19 #include "pool.h"
20 #include "poolid.h"
21 #include "poolvendor.h"
22 #include "util.h"
23
24 const char *vendors[] = {
25   "!openSUSE Build Service*",
26   "SUSE*",
27   "openSUSE*",
28   "SGI*",
29   "Novell*",
30   "Silicon Graphics*",
31   "Jpackage Project*",
32   "ATI Technologies Inc.*",
33   "Nvidia*",
34   0,
35   0,
36 };
37
38 Id pool_vendor2mask(Pool *pool, Id vendor)
39 {
40   const char *vstr;
41   int i;
42   Id mask, m;
43   const char **v, *vs;
44
45   if (vendor == 0)
46     return 0;
47   for (i = 0; i < pool->vendormap.count; i += 2)
48     if (pool->vendormap.elements[i] == vendor)
49       return pool->vendormap.elements[i + 1];
50   vstr = id2str(pool, vendor);
51   m = 1;
52   mask = 0;
53   for (v = vendors; ; v++)
54     {
55       vs = *v;
56       if (vs == 0)      /* end of block? */
57         {
58           v++;
59           if (*v == 0)
60             break;
61           if (m == (1 << 31))
62             break;
63           m <<= 1;      /* next vendor equivalence class */
64         }
65       if (fnmatch(*vs == '!' ? vs + 1 : vs, vstr, FNM_CASEFOLD) == 0)
66         {
67           if (*vs != '!')
68             mask |= m;
69           while (v[1])  /* forward to next block */
70             v++;
71         }
72     }
73   queue_push(&pool->vendormap, vendor);
74   queue_push(&pool->vendormap, mask);
75   return mask;
76 }