bah revert... you dreamer
[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   "SUSE*",
26   "openSUSE*",
27   "SGI*",
28   "Novell*",
29   "Silicon Graphics*",
30   "Jpackage Project*",
31   "ATI Technologies Inc.*",
32   "Nvidia*",
33   0,
34   0,
35 };
36
37 Id pool_vendor2mask(Pool *pool, Id vendor)
38 {
39   const char *vstr;
40   int i;
41   Id mask, m;
42   const char **v;
43
44   if (vendor == 0)
45     return 0;
46   for (i = 0; i < pool->vendormap.count; i += 2)
47     if (pool->vendormap.elements[i] == vendor)
48       return pool->vendormap.elements[i + 1];
49   vstr = id2str(pool, vendor);
50   m = 1;
51   mask = 0;
52   for (v = vendors; ; v++)
53     {
54       if (*v == 0)
55         {
56           v++;
57           if (*v == 0)
58             break;
59           if (m == (1 << 31))
60             break;
61           m <<= 1;
62         }
63       if (fnmatch(*v, vstr, FNM_CASEFOLD) == 0)
64         {
65           mask |= m;
66           while (v[1])
67             v++;
68         }
69     }
70   queue_push(&pool->vendormap, vendor);
71   queue_push(&pool->vendormap, mask);
72   return mask;
73 }