satsolver
0.17.2
Main Page
Related Pages
Classes
Files
File List
File Members
src
poolarch.c
Go to the documentation of this file.
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
static
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
"armv7nhl"
,
"armv7nhl:armv7hl"
,
35
"armv7hl"
,
"armv7hl"
,
36
"armv7l"
,
"armv7l:armv6l:armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l"
,
37
"armv6l"
,
"armv6l:armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l"
,
38
"armv5tejl"
,
"armv5tejl:armv5tel:armv5l:armv4tl:armv4l:armv3l"
,
39
"armv5tel"
,
"armv5tel:armv5l:armv4tl:armv4l:armv3l"
,
40
"armv5l"
,
"armv5l:armv4tl:armv4l:armv3l"
,
41
"armv4tl"
,
"armv4tl:armv4l:armv3l"
,
42
"armv4l"
,
"armv4l:armv3l"
,
43
"armv3l"
,
"armv3l"
,
44
"sh3"
,
"sh3"
,
45
"sh4"
,
"sh4"
,
46
"sh4a"
,
"sh4a:sh4"
,
47
"sparc64v"
,
"sparc64v:sparc64:sparcv9v:sparcv9:sparcv8:sparc"
,
48
"sparc64"
,
"sparc64:sparcv9:sparcv8:sparc"
,
49
"sparcv9v"
,
"sparcv9v:sparcv9:sparcv8:sparc"
,
50
"sparcv9"
,
"sparcv9:sparcv8:sparc"
,
51
"sparcv8"
,
"sparcv8:sparc"
,
52
"sparc"
,
"sparc"
,
53
0
54
};
55
56
void
57
pool_setarch
(
Pool
*pool,
const
char
*arch)
58
{
59
if
(arch)
60
{
61
int
i;
62
63
/* convert arch to known policy */
64
for
(i = 0;
archpolicies
[i]; i += 2)
65
if
(!strcmp(
archpolicies
[i], arch))
66
break
;
67
if
(
archpolicies
[i])
68
arch =
archpolicies
[i + 1];
69
else
70
arch =
""
;
71
}
72
pool_setarchpolicy
(pool, arch);
73
}
74
75
/*
76
* we support three relations:
77
*
78
* a = b both architectures a and b are treated as equivalent
79
* a > b a is considered a "better" architecture, the solver
80
* should change from a to b, but must not change from b to a
81
* a : b a is considered a "better" architecture, the solver
82
* must not change the architecture from a to b or b to a
83
*/
84
void
85
pool_setarchpolicy
(
Pool
*pool,
const
char
*arch)
86
{
87
unsigned
int
score = 0x10001;
88
size_t
l;
89
char
d;
90
Id
*id2arch;
91
Id
id, lastarch;
92
93
pool->
id2arch
=
sat_free
(pool->
id2arch
);
94
pool->
id2color
=
sat_free
(pool->
id2color
);
95
if
(!arch)
96
{
97
pool->
lastarch
= 0;
98
return
;
99
}
100
#ifndef DEBIAN_SEMANTICS
101
id
= ARCH_NOARCH;
102
#else
103
id
= ARCH_ALL;
104
#endif
105
lastarch =
id
+ 255;
106
id2arch =
sat_calloc
(lastarch + 1,
sizeof
(
Id
));
107
id2arch[id] = 1;
/* the "noarch" class */
108
109
d = 0;
110
while
(*arch)
111
{
112
l = strcspn(arch,
":=>"
);
113
if
(l)
114
{
115
id
=
strn2id
(pool, arch, l, 1);
116
if
(
id
> lastarch)
117
{
118
id2arch =
sat_realloc2
(id2arch, (
id
+ 255 + 1),
sizeof
(
Id
));
119
memset(id2arch + lastarch + 1, 0, (
id
+ 255 - lastarch) *
sizeof
(
Id
));
120
lastarch =
id
+ 255;
121
}
122
if
(id2arch[
id
] == 0)
123
{
124
if
(d ==
':'
)
125
score += 0x10000;
126
else
if
(d ==
'>'
)
127
score += 0x00001;
128
id2arch[id] = score;
129
}
130
}
131
arch += l;
132
if
((d = *arch++) == 0)
133
break
;
134
}
135
pool->
id2arch
= id2arch;
136
pool->
lastarch
= lastarch;
137
}
138
139
unsigned
char
140
pool_arch2color_slow
(
Pool
*pool,
Id
arch)
141
{
142
const
char
*s;
143
unsigned
char
color;
144
145
if
(arch > pool->
lastarch
)
146
return
ARCHCOLOR_ALL
;
147
if
(!pool->
id2color
)
148
pool->
id2color
=
sat_calloc
(pool->
lastarch
+ 1, 1);
149
s =
id2str
(pool, arch);
150
if
(arch == ARCH_NOARCH || arch == ARCH_ALL)
151
color =
ARCHCOLOR_ALL
;
152
else
if
(!strcmp(s,
"s390x"
) || strstr(s,
"64"
))
153
color =
ARCHCOLOR_64
;
154
else
155
color =
ARCHCOLOR_32
;
156
return
color;
157
}
158
Generated by
1.8.4