Imported Upstream version 0.6.20
[platform/upstream/libsolv.git] / src / solver_private.h
1 /*
2  * Copyright (c) 2011, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * solver_private.h - private functions
10  *
11  */
12
13 #ifndef LIBSOLV_SOLVER_PRIVATE_H
14 #define LIBSOLV_SOLVER_PRIVATE_H
15
16 extern void solver_run_sat(Solver *solv, int disablerules, int doweak);
17 extern void solver_reset(Solver *solv);
18
19 extern int solver_splitprovides(Solver *solv, Id dep, Map *m);
20
21 static inline int
22 solver_dep_fulfilled(Solver *solv, Id dep)
23 {
24   Pool *pool = solv->pool;
25   Id p, pp;
26
27   if (ISRELDEP(dep))
28     {
29       Reldep *rd = GETRELDEP(pool, dep);
30       if (rd->flags == REL_COND)
31         {
32           if (ISRELDEP(rd->evr))
33             {
34               Reldep *rd2 = GETRELDEP(pool, rd->evr);
35               if (rd2->flags == REL_ELSE)
36                 {
37                   if (solver_dep_fulfilled(solv, rd2->name))
38                     return solver_dep_fulfilled(solv, rd->name);
39                   return solver_dep_fulfilled(solv, rd2->evr);
40                 }
41             }
42           if (solver_dep_fulfilled(solv, rd->name))
43             return 1;
44           return !solver_dep_fulfilled(solv, rd->evr);
45         }
46       if (rd->flags == REL_AND)
47         {
48           if (!solver_dep_fulfilled(solv, rd->name))
49             return 0;
50           return solver_dep_fulfilled(solv, rd->evr);
51         }
52       if (rd->flags == REL_OR)
53         {
54           if (solver_dep_fulfilled(solv, rd->name))
55             return 1;
56           return solver_dep_fulfilled(solv, rd->evr);
57         }
58       if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_SPLITPROVIDES)
59         return solver_splitprovides(solv, rd->evr, 0);
60     }
61   FOR_PROVIDES(p, pp, dep)
62     {
63       if (solv->decisionmap[p] > 0)
64         return 1;
65     }
66   return 0;
67 }
68
69 static inline int
70 solver_is_supplementing(Solver *solv, Solvable *s)
71 {
72   Id sup, *supp;
73   if (!s->supplements)
74     return 0;
75   supp = s->repo->idarraydata + s->supplements;
76   while ((sup = *supp++) != 0)
77     if (solver_dep_fulfilled(solv, sup))
78       return 1;
79   return 0;
80 }
81
82 static inline int
83 solver_is_enhancing(Solver *solv, Solvable *s)
84 {
85   Id enh, *enhp;
86   if (!s->enhances)
87     return 0;
88   enhp = s->repo->idarraydata + s->enhances;
89   while ((enh = *enhp++) != 0)
90     if (solver_dep_fulfilled(solv, enh))
91       return 1;
92   return 0;
93 }
94
95 #endif /* LIBSOLV_SOLVER_PRIVATE_H */