fix conflict
[platform/upstream/libsolv.git] / src / poolarch.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 /*
9  * poolarch.c
10  *
11  * create architecture policies
12  */
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17
18 #include "pool.h"
19 #include "poolid.h"
20 #include "poolarch.h"
21 #include "util.h"
22
23 const char *archpolicies[] = {
24   "x86_64",     "x86_64:i686:i586:i486:i386",
25   "i686",       "i686:i586:i486:i386",
26   "i586",       "i586:i486:i386",
27   "i486",       "i486:i386",
28   "i386",       "i386",
29   "s390x",      "s390x:s390",
30   "s390",       "s390",
31   "ia64",       "ia64:i686:i586:i486:i386",
32   "ppc64",      "ppc64:ppc",
33   "ppc",        "ppc",
34   "armv6l",     "armv6l:armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l",
35   "armv5tejl",  "armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l",
36   "armv5tel",   "armv5tel:armv5l:armv4tl:armv4l:armv3l",
37   "armv5l",     "armv5l:armv4tl:armv4l:armv3l",
38   "armv4tl",    "armv4tl:armv4l:armv3l",
39   "armv4l",     "armv4l:armv3l",
40   "armv3l",     "armv3l",
41   "sh3",        "sh3",
42   "sh4",        "sh4",
43   "sh4a",       "sh4a:sh4",
44   "sparc64v",   "sparc64v:sparc64:sparcv9v:sparcv9:sparcv8:sparc",
45   "sparc64",    "sparc64:sparcv9:sparcv8:sparc",
46   "sparcv9v",   "sparcv9v:sparcv9:sparcv8:sparc",
47   "sparcv9",    "sparcv9:sparcv8:sparc",
48   "sparcv8",    "sparcv8:sparc",
49   "sparc",      "sparc",
50   0
51 };
52
53 void
54 pool_setarch(Pool *pool, const char *arch)
55 {
56   const char *a;
57   unsigned int score = 0x10001;
58   size_t l;
59   char d;
60   int i;
61   Id *id2arch;
62   Id id, lastarch;
63
64   pool->id2arch = sat_free(pool->id2arch);
65   pool->id2color = sat_free(pool->id2color);
66   if (!arch)
67     {
68       pool->lastarch = 0;
69       return;
70     }
71 #ifndef DEBIAN_SEMANTICS
72   id = ARCH_NOARCH;
73 #else
74   id = ARCH_ALL;
75 #endif
76   lastarch = id + 255;
77   id2arch = sat_calloc(lastarch + 1, sizeof(Id));
78   id2arch[id] = 1;
79
80   a = "";
81   for (i = 0; archpolicies[i]; i += 2)
82     if (!strcmp(archpolicies[i], arch))
83       break;
84   if (archpolicies[i])
85     a = archpolicies[i + 1];
86   d = 0;
87   while (*a)
88     {
89       l = strcspn(a, ":=>");
90       if (l)
91         {
92           id = strn2id(pool, a, l, 1);
93           if (id > lastarch)
94             {
95               id2arch = sat_realloc(id2arch, (id + 255 + 1) * sizeof(Id));
96               memset(id2arch + lastarch + 1, 0, (id + 255 - lastarch) * sizeof(Id));
97               lastarch = id + 255;
98             }
99           if (id2arch[id] == 0)
100             {
101               if (d == ':')
102                 score += 0x10000;
103               else if (d == '>')
104                 score += 0x00001;
105               id2arch[id] = score;
106             }
107         }
108       a += l;
109       if ((d = *a++) == 0)
110         break;
111     }
112   pool->id2arch = id2arch;
113   pool->lastarch = lastarch;
114 }
115
116 unsigned char
117 pool_arch2color_slow(Pool *pool, Id arch)
118 {
119   const char *s;
120   unsigned char color;
121
122   if (arch > pool->lastarch)
123     return ARCHCOLOR_ALL;
124   if (!pool->id2color)
125     pool->id2color = sat_calloc(pool->lastarch + 1, 1);
126   s = id2str(pool, arch);
127   if (arch == ARCH_NOARCH || arch == ARCH_ALL)
128     color = ARCHCOLOR_ALL;
129   else if (!strcmp(s, "s390x") || strstr(s, "64"))
130     color = ARCHCOLOR_64;
131   else
132     color = ARCHCOLOR_32;
133   return color;
134 }
135