poolvendor.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2007, Novell Inc.
00003  *
00004  * This program is licensed under the BSD license, read LICENSE.BSD
00005  * for further information
00006  */
00007 
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 
00012 /* we need FNM_CASEFOLD */
00013 #ifndef _GNU_SOURCE
00014 #define _GNU_SOURCE
00015 #endif
00016 
00017 #include <fnmatch.h>
00018 
00019 #include "pool.h"
00020 #include "poolid.h"
00021 #include "poolvendor.h"
00022 #include "util.h"
00023 
00024 const char *vendors[] = {
00025   "!openSUSE Build Service*",
00026   "SUSE*",
00027   "openSUSE*",
00028   "SGI*",
00029   "Novell*",
00030   "Silicon Graphics*",
00031   "Jpackage Project*",
00032   "ATI Technologies Inc.*",
00033   "Nvidia*",
00034   0,
00035   0,
00036 };
00037 
00038 Id pool_vendor2mask(Pool *pool, Id vendor)
00039 {
00040   const char *vstr;
00041   int i;
00042   Id mask, m;
00043   const char **v, *vs;
00044 
00045   if (vendor == 0)
00046     return 0;
00047   for (i = 0; i < pool->vendormap.count; i += 2)
00048     if (pool->vendormap.elements[i] == vendor)
00049       return pool->vendormap.elements[i + 1];
00050   vstr = id2str(pool, vendor);
00051   m = 1;
00052   mask = 0;
00053   for (v = vendors; ; v++)
00054     {
00055       vs = *v;
00056       if (vs == 0)      /* end of block? */
00057         {
00058           v++;
00059           if (*v == 0)
00060             break;
00061           if (m == (1 << 31))
00062             break;
00063           m <<= 1;      /* next vendor equivalence class */
00064         }
00065       if (fnmatch(*vs == '!' ? vs + 1 : vs, vstr, FNM_CASEFOLD) == 0)
00066         {
00067           if (*vs != '!')
00068             mask |= m;
00069           while (v[1])  /* forward to next block */
00070             v++;
00071         }
00072     }
00073   queue_push(&pool->vendormap, vendor);
00074   queue_push(&pool->vendormap, mask);
00075   return mask;
00076 }

doxygen