diff options
author | Klaus Kaempf <kkaempf@suse.de> | 2007-10-02 12:40:07 +0000 |
---|---|---|
committer | Klaus Kaempf <kkaempf@suse.de> | 2007-10-02 12:40:07 +0000 |
commit | 8f8a9ed5192a6737d63364029cb05d91f1d0e399 (patch) | |
tree | 287434efe18f662976f8dad334d489dd60ff6e88 /src/poolarch.c | |
download | libsolv-8f8a9ed5192a6737d63364029cb05d91f1d0e399.tar.gz libsolv-8f8a9ed5192a6737d63364029cb05d91f1d0e399.tar.bz2 libsolv-8f8a9ed5192a6737d63364029cb05d91f1d0e399.zip |
current state of 'sat-solver'
Diffstat (limited to 'src/poolarch.c')
-rw-r--r-- | src/poolarch.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/poolarch.c b/src/poolarch.c new file mode 100644 index 0000000..ec41013 --- /dev/null +++ b/src/poolarch.c @@ -0,0 +1,84 @@ +/* + * poolarch.c + * + * create architecture policies + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "pool.h" +#include "poolid.h" +#include "poolarch.h" +#include "util.h" + +const char *archpolicies[] = { + "x86_64", "x86_64:i686:i585:i486:i386", + "i686", "i686:i585:i486:i386", + "i586", "i585:i486:i386", + "i486", "i486:i386", + "i386", "i386", + 0 +}; + +void +pool_setarch(Pool *pool, const char *arch) +{ + const char *a; + char buf[256]; + unsigned int score = 0x10001; + size_t l; + char d; + int i; + Id *id2arch; + Id id, lastarch; + + pool->id2arch = xfree(pool->id2arch); + if (!arch) + { + pool->lastarch = 0; + return; + } + id = ARCH_NOARCH; + lastarch = id + 255; + id2arch = xcalloc(lastarch + 1, sizeof(Id)); + id2arch[id] = 1; + + a = ""; + for (i = 0; archpolicies[i]; i += 2) + if (!strcmp(archpolicies[i], arch)) + break; + if (archpolicies[i]) + a = archpolicies[i + 1]; + d = 0; + while (*a) + { + l = strcspn(a, ":=>"); + if (l && l < sizeof(buf) - 1) + { + strncpy(buf, a, l); + buf[l] = 0; + id = str2id(pool, buf, 1); + if (id > lastarch) + { + id2arch = xrealloc(id2arch, (id + 255 + 1) * sizeof(Id)); + memset(id2arch + lastarch + 1, 0, (id + 255 - lastarch) * sizeof(Id)); + lastarch = id + 255; + } + if (id2arch[id] == 0) + { + if (d == ':') + score += 0x10000; + else if (d == '>') + score += 0x00001; + id2arch[id] = score; + } + } + a += l; + if ((d = *a++) == 0) + break; + } + pool->id2arch = id2arch; + pool->lastarch = lastarch; +} |