2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
19 #include "repo_content.h"
22 split(char *l, char **sp, int m)
27 while (*l == ' ' || *l == '\t')
34 while (*l && !(*l == ' ' || *l == '\t'))
51 makeevr(Pool *pool, char *s)
53 if (!strncmp(s, "0:", 2) && s[2])
55 return str2id(pool, s, 1);
58 static char *flagtab[] = {
68 join(struct parsedata *pd, char *s1, char *s2, char *s3)
83 pd->tmp = malloc(pd->tmpl);
85 pd->tmp = realloc(pd->tmp, pd->tmpl);
107 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, int isreq)
116 /* Name [relop evr [rest]] --> 1, 3 or 4 fields. */
117 words += split(line, sp + words, 4 - words);
120 fprintf(stderr, "Bad dependency line: %s\n", line);
124 /* Hack, as the content file adds 'package:' for package
125 dependencies sometimes. */
126 if (!strncmp (sp[0], "package:", 8))
128 id = str2id(pool, sp[0], 1);
129 if (words >= 3 && strpbrk (sp[1], "<>="))
131 evrid = makeevr(pool, sp[2]);
132 for (flags = 0; flags < 6; flags++)
133 if (!strcmp(sp[1], flagtab[flags]))
137 fprintf(stderr, "Unknown relation '%s'\n", sp[1]);
140 id = rel2id(pool, id, evrid, flags + 1, 1);
141 /* Consume three words, there's nothing to move to front. */
143 line = sp[3], words = 0;
148 /* Consume one word. If we had more move them to front. */
150 for (j = 0; j < words; j++)
153 line = sp[2], words = 2;
155 olddeps = repo_addid_dep(pd->repo, olddeps, id, isreq);
163 repo_add_content(Repo *repo, FILE *fp)
165 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 s = pool_id2solvable(pool, repo_add_solvable(repo));
221 s->name = str2id(pool, join(&pd, pd.kind, ":", value), 1);
223 else if (istag ("VERSION"))
224 /* without a release? but that's like zypp implements it */
225 s->evr = makeevr(pool, value);
226 else if (istag ("DISTPRODUCT"))
227 ; /* DISTPRODUCT is only for Yast, not the package manager */
228 else if (istag ("DISTVERSION"))
229 ; /* DISTVERSION is only for Yast, not the package manager */
230 else if (istag ("VENDOR"))
231 s->vendor = str2id(pool, value, 1);
232 else if (istag ("ARCH"))
233 /* Theoretically we want to have the best arch of the given
234 modifiers which still is compatible with the system
235 arch. We don't know the latter here, though. */
236 s->arch = ARCH_NOARCH;
237 else if (istag ("PREREQUIRES"))
238 s->requires = adddep(pool, &pd, s->requires, value, 2);
239 else if (istag ("REQUIRES"))
240 s->requires = adddep(pool, &pd, s->requires, value, 1);
241 else if (istag ("PROVIDES"))
242 s->provides = adddep(pool, &pd, s->provides, value, 0);
243 else if (istag ("CONFLICTS"))
244 s->conflicts = adddep(pool, &pd, s->conflicts, value, 0);
245 else if (istag ("OBSOLETES"))
246 s->obsoletes = adddep(pool, &pd, s->obsoletes, value, 0);
247 else if (istag ("RECOMMENDS"))
248 s->recommends = adddep(pool, &pd, s->recommends, value, 0);
249 else if (istag ("SUGGESTS"))
250 s->suggests = adddep(pool, &pd, s->suggests, value, 0);
251 else if (istag ("SUPPLEMENTS"))
252 s->supplements = adddep(pool, &pd, s->supplements, value, 0);
253 else if (istag ("ENHANCES"))
254 s->enhances = adddep(pool, &pd, s->enhances, value, 0);
255 /* FRESHENS doesn't seem to exist. */
256 /* XXX do something about LINGUAS and ARCH? */
260 fprintf (stderr, "malformed line: %s\n", line);
263 if (s && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
264 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
266 s->supplements = repo_fix_legacy(repo, s->provides, s->supplements);