2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
18 #include "repo_content.h"
23 split(char *l, char **sp, int m)
28 while (*l == ' ' || *l == '\t')
35 while (*l && !(*l == ' ' || *l == '\t'))
52 makeevr(Pool *pool, char *s)
54 if (!strncmp(s, "0:", 2) && s[2])
56 return str2id(pool, s, 1);
59 static char *flagtab[] = {
69 join(struct parsedata *pd, char *s1, char *s2, char *s3)
84 pd->tmp = malloc(pd->tmpl);
86 pd->tmp = realloc(pd->tmp, pd->tmpl);
108 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, int isreq)
117 /* Name [relop evr [rest]] --> 1, 3 or 4 fields. */
118 words += split(line, sp + words, 4 - words);
121 fprintf(stderr, "Bad dependency line: %s\n", line);
125 /* Hack, as the content file adds 'package:' for package
126 dependencies sometimes. */
127 if (!strncmp (sp[0], "package:", 8))
129 id = str2id(pool, sp[0], 1);
130 if (words >= 3 && strpbrk (sp[1], "<>="))
132 evrid = makeevr(pool, sp[2]);
133 for (flags = 0; flags < 6; flags++)
134 if (!strcmp(sp[1], flagtab[flags]))
138 fprintf(stderr, "Unknown relation '%s'\n", sp[1]);
141 id = rel2id(pool, id, evrid, flags + 1, 1);
142 /* Consume three words, there's nothing to move to front. */
144 line = sp[3], words = 0;
149 /* Consume one word. If we had more move them to front. */
151 for (j = 0; j < words; j++)
154 line = sp[2], words = 2;
156 olddeps = repo_addid_dep(pd->repo, olddeps, id, isreq);
164 repo_add_content(Repo *repo, FILE *fp)
166 Pool *pool = repo->pool;
173 memset(&pd, 0, sizeof(pd));
174 line = xmalloc(1024);
185 if (linep - line + 16 > aline)
187 aline = linep - line;
188 line = realloc(line, aline + 512);
189 linep = line + aline;
192 if (!fgets(linep, aline - (linep - line), fp))
194 linep += strlen(linep);
195 if (linep == line || linep[-1] != '\n')
199 if (split (line, fields, 2) == 2)
201 char *key = fields[0];
202 char *value = fields[1];
203 char *modifier = strchr (key, '.');
208 fprintf (stderr, "key %s, mod %s, value %s\n", key, modifier, fields[1]);
210 fprintf (stderr, "key %s, value %s\n", key, fields[1]);
213 #define istag(x) !strcmp (key, x)
214 if (istag ("PRODUCT"))
216 if (s && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
217 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
219 s->supplements = repo_fix_legacy(repo, s->provides, s->supplements);
220 /* Only support one product. */
222 if ((pack & PACK_BLOCK) == 0)
224 pool->solvables = realloc(pool->solvables, (pool->nsolvables + pack + PACK_BLOCK + 1) * sizeof(Solvable));
225 memset(pool->solvables + pool->nsolvables + pack, 0, (PACK_BLOCK + 1) * sizeof(Solvable));
227 s = pool->solvables + pool->nsolvables + pack;
229 s->name = str2id(pool, join(&pd, pd.kind, ":", value), 1);
232 else if (istag ("VERSION"))
233 /* without a release? but that's like zypp implements it */
234 s->evr = makeevr(pool, value);
235 else if (istag ("DISTPRODUCT"))
236 ; /* DISTPRODUCT is only for Yast, not the package manager */
237 else if (istag ("DISTVERSION"))
238 ; /* DISTVERSION is only for Yast, not the package manager */
239 else if (istag ("VENDOR"))
240 s->vendor = str2id(pool, value, 1);
241 else if (istag ("ARCH"))
242 /* Theoretically we want to have the best arch of the given
243 modifiers which still is compatible with the system
244 arch. We don't know the latter here, though. */
245 s->arch = ARCH_NOARCH;
246 else if (istag ("PREREQUIRES"))
247 s->requires = adddep(pool, &pd, s->requires, value, 2);
248 else if (istag ("REQUIRES"))
249 s->requires = adddep(pool, &pd, s->requires, value, 1);
250 else if (istag ("PROVIDES"))
251 s->provides = adddep(pool, &pd, s->provides, value, 0);
252 else if (istag ("CONFLICTS"))
253 s->conflicts = adddep(pool, &pd, s->conflicts, value, 0);
254 else if (istag ("OBSOLETES"))
255 s->obsoletes = adddep(pool, &pd, s->obsoletes, value, 0);
256 else if (istag ("RECOMMENDS"))
257 s->recommends = adddep(pool, &pd, s->recommends, value, 0);
258 else if (istag ("SUGGESTS"))
259 s->suggests = adddep(pool, &pd, s->suggests, value, 0);
260 else if (istag ("SUPPLEMENTS"))
261 s->supplements = adddep(pool, &pd, s->supplements, value, 0);
262 else if (istag ("ENHANCES"))
263 s->enhances = adddep(pool, &pd, s->enhances, value, 0);
264 /* FRESHENS doesn't seem to exist. */
265 /* XXX do something about LINGUAS and ARCH? */
269 fprintf (stderr, "malformed line: %s\n", line);
272 if (s && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
273 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
275 s->supplements = repo_fix_legacy(repo, s->provides, s->supplements);
277 pool->nsolvables += pack;
278 repo->nsolvables += pack;