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 /*
00025  *  const char *vendorsclasses[] = {
00026  *    "!openSUSE Build Service*",
00027  *    "SUSE*",
00028  *    "openSUSE*",
00029  *    "SGI*",
00030  *    "Novell*",
00031  *    "Silicon Graphics*",
00032  *    "Jpackage Project*",
00033  *    "ATI Technologies Inc.*",
00034  *    "Nvidia*",
00035  *    0,
00036  *    0,
00037  *  };
00038  */
00039 
00040 /* allows for 32 different vendor classes */
00041 
00042 Id pool_vendor2mask(Pool *pool, Id vendor)
00043 {
00044   const char *vstr;
00045   int i;
00046   Id mask, m;
00047   const char **v, *vs;
00048 
00049   if (vendor == 0 || !pool->vendorclasses)
00050     return 0;
00051   for (i = 0; i < pool->vendormap.count; i += 2)
00052     if (pool->vendormap.elements[i] == vendor)
00053       return pool->vendormap.elements[i + 1];
00054   vstr = id2str(pool, vendor);
00055   m = 1;
00056   mask = 0;
00057   for (v = pool->vendorclasses; ; v++)
00058     {
00059       vs = *v;
00060       if (vs == 0)      /* end of block? */
00061         {
00062           v++;
00063           if (*v == 0)
00064             break;
00065           if (m == (1 << 31))
00066             break;      /* sorry, out of bits */
00067           m <<= 1;      /* next vendor equivalence class */
00068         }
00069       if (fnmatch(*vs == '!' ? vs + 1 : vs, vstr, FNM_CASEFOLD) == 0)
00070         {
00071           if (*vs != '!')
00072             mask |= m;
00073           while (v[1])  /* forward to next block */
00074             v++;
00075         }
00076     }
00077   queue_push(&pool->vendormap, vendor);
00078   queue_push(&pool->vendormap, mask);
00079   return mask;
00080 }
00081 
00082 void
00083 pool_setvendorclasses(Pool *pool, const char **vendorclasses)
00084 {
00085   int i;
00086   const char **v;
00087 
00088   if (pool->vendorclasses)
00089     {
00090       for (v = pool->vendorclasses; v[0] || v[1]; v++)
00091         sat_free((void *)*v);
00092       pool->vendorclasses = sat_free(pool->vendorclasses);
00093     }
00094   if (!vendorclasses || !vendorclasses[0])
00095     return;
00096   for (v = vendorclasses; v[0] || v[1]; v++)
00097     ;
00098   pool->vendorclasses = sat_calloc(v - vendorclasses + 2, sizeof(const char *));
00099   for (v = vendorclasses, i = 0; v[0] || v[1]; v++, i++)
00100     pool->vendorclasses[i] = *v ? strdup(*v) : 0;
00101   pool->vendorclasses[i++] = 0;
00102   pool->vendorclasses[i] = 0;
00103   queue_empty(&pool->vendormap);
00104 }
00105 

Generated on Mon Dec 15 17:56:24 2014 for satsolver by  doxygen 1.5.6