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"
21 split(char *l, char **sp, int m)
26 while (*l == ' ' || *l == '\t')
33 while (*l && !(*l == ' ' || *l == '\t'))
50 makeevr(Pool *pool, char *s)
52 if (!strncmp(s, "0:", 2) && s[2])
54 return str2id(pool, s, 1);
57 static char *flagtab[] = {
67 join(struct parsedata *pd, char *s1, char *s2, char *s3)
82 pd->tmp = malloc(pd->tmpl);
84 pd->tmp = realloc(pd->tmp, pd->tmpl);
106 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, int isreq)
115 /* Name [relop evr [rest]] --> 1, 3 or 4 fields. */
116 words += split(line, sp + words, 4 - words);
119 fprintf(stderr, "Bad dependency line: %s\n", line);
123 /* Hack, as the content file adds 'package:' for package
124 dependencies sometimes. */
125 if (!strncmp (sp[0], "package:", 8))
127 id = str2id(pool, sp[0], 1);
128 if (words >= 3 && strpbrk (sp[1], "<>="))
130 evrid = makeevr(pool, sp[2]);
131 for (flags = 0; flags < 6; flags++)
132 if (!strcmp(sp[1], flagtab[flags]))
136 fprintf(stderr, "Unknown relation '%s'\n", sp[1]);
139 id = rel2id(pool, id, evrid, flags + 1, 1);
140 /* Consume three words, there's nothing to move to front. */
142 line = sp[3], words = 0;
147 /* Consume one word. If we had more move them to front. */
149 for (j = 0; j < words; j++)
152 line = sp[2], words = 2;
154 olddeps = repo_addid_dep(pd->repo, olddeps, id, isreq);
162 repo_add_content(Repo *repo, FILE *fp)
164 Pool *pool = repo->pool;
171 memset(&pd, 0, sizeof(pd));
172 line = xmalloc(1024);
182 if (linep - line + 16 > aline)
184 aline = linep - line;
185 line = realloc(line, aline + 512);
186 linep = line + aline;
189 if (!fgets(linep, aline - (linep - line), fp))
191 linep += strlen(linep);
192 if (linep == line || linep[-1] != '\n')
196 if (split (line, fields, 2) == 2)
198 char *key = fields[0];
199 char *value = fields[1];
200 char *modifier = strchr (key, '.');
205 fprintf (stderr, "key %s, mod %s, value %s\n", key, modifier, fields[1]);
207 fprintf (stderr, "key %s, value %s\n", key, fields[1]);
210 #define istag(x) !strcmp (key, x)
211 if (istag ("PRODUCT"))
213 /* finish old solvable */
214 if (s && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
215 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
217 s->supplements = repo_fix_legacy(repo, s->provides, s->supplements);
218 /* Only support one product. */
220 id = repo_add_solvable(repo);
221 s = pool->solvables + id;
224 s->name = str2id(pool, join(&pd, pd.kind, ":", value), 1);
226 else if (istag ("VERSION"))
227 /* without a release? but that's like zypp implements it */
228 s->evr = makeevr(pool, value);
229 else if (istag ("DISTPRODUCT"))
230 ; /* DISTPRODUCT is only for Yast, not the package manager */
231 else if (istag ("DISTVERSION"))
232 ; /* DISTVERSION is only for Yast, not the package manager */
233 else if (istag ("VENDOR"))
234 s->vendor = str2id(pool, value, 1);
235 else if (istag ("ARCH"))
236 /* Theoretically we want to have the best arch of the given
237 modifiers which still is compatible with the system
238 arch. We don't know the latter here, though. */
239 s->arch = ARCH_NOARCH;
240 else if (istag ("PREREQUIRES"))
241 s->requires = adddep(pool, &pd, s->requires, value, 2);
242 else if (istag ("REQUIRES"))
243 s->requires = adddep(pool, &pd, s->requires, value, 1);
244 else if (istag ("PROVIDES"))
245 s->provides = adddep(pool, &pd, s->provides, value, 0);
246 else if (istag ("CONFLICTS"))
247 s->conflicts = adddep(pool, &pd, s->conflicts, value, 0);
248 else if (istag ("OBSOLETES"))
249 s->obsoletes = adddep(pool, &pd, s->obsoletes, value, 0);
250 else if (istag ("RECOMMENDS"))
251 s->recommends = adddep(pool, &pd, s->recommends, value, 0);
252 else if (istag ("SUGGESTS"))
253 s->suggests = adddep(pool, &pd, s->suggests, value, 0);
254 else if (istag ("SUPPLEMENTS"))
255 s->supplements = adddep(pool, &pd, s->supplements, value, 0);
256 else if (istag ("ENHANCES"))
257 s->enhances = adddep(pool, &pd, s->enhances, value, 0);
258 /* FRESHENS doesn't seem to exist. */
259 /* XXX do something about LINGUAS and ARCH? */
263 fprintf (stderr, "malformed line: %s\n", line);
266 if (s && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
267 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
269 s->supplements = repo_fix_legacy(repo, s->provides, s->supplements);