97fac9f8fa4f000ae2a91ed8b46157373b14b02b
[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 #define _GNU_SOURCE 1
13 #include <fnmatch.h>
14
15 #include "pool.h"
16 #include "poolid.h"
17 #include "poolvendor.h"
18 #include "util.h"
19
20 const char *vendors[] = {
21   "SUSE*",
22   "openSUSE*",
23   "SGI*",
24   "Novell*",
25   "Silicon Graphics*",
26   "Jpackage Project*",
27   "ATI Technologies Inc.*",
28   "Nvidia*",
29   0,
30   0,
31 };
32
33 Id pool_vendor2mask(Pool *pool, Id vendor)
34 {
35   const char *vstr;
36   int i;
37   Id mask, m;
38   const char **v;
39
40   if (vendor == 0)
41     return 0;
42   for (i = 0; i < pool->vendormap.count; i += 2)
43     if (pool->vendormap.elements[i] == vendor)
44       return pool->vendormap.elements[i + 1];
45   vstr = id2str(pool, vendor);
46   m = 1;
47   mask = 0;
48   for (v = vendors; ; v++)
49     {
50       if (*v == 0)
51         {
52           v++;
53           if (*v == 0)
54             break;
55           if (m == (1 << 31))
56             break;
57           m <<= 1;
58         }
59       if (fnmatch(*v, vstr, FNM_CASEFOLD) == 0)
60         {
61           mask |= m;
62           while (v[1])
63             v++;
64         }
65     }
66   queue_push(&pool->vendormap, vendor);
67   queue_push(&pool->vendormap, mask);
68   return mask;
69 }