2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
16 #include "attr_store.h"
17 #include "repo_susetags.h"
19 #define PACK_BLOCK 255
22 split(char *l, char **sp, int m)
32 while (*l && *l != ' ')
49 makeevr(Pool *pool, char *s)
51 if (!strncmp(s, "0:", 2) && s[2])
53 return str2id(pool, s, 1);
56 static char *flagtab[] = {
66 join(struct parsedata *pd, char *s1, char *s2, char *s3)
81 pd->tmp = malloc(pd->tmpl);
83 pd->tmp = realloc(pd->tmp, pd->tmpl);
105 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, int isreq, char *kind)
111 i = split(line + 5, sp, 4);
112 if (i != 1 && i != 3)
114 fprintf(stderr, "Bad dependency line: %s\n", line);
118 id = str2id(pool, join(pd, kind, ":", sp[0]), 1);
120 id = str2id(pool, sp[0], 1);
123 evrid = makeevr(pool, sp[2]);
124 for (flags = 0; flags < 6; flags++)
125 if (!strcmp(sp[1], flagtab[flags]))
129 fprintf(stderr, "Unknown relation '%s'\n", sp[1]);
132 id = rel2id(pool, id, evrid, flags + 1, 1);
134 return repo_addid_dep(pd->repo, olddeps, id, isreq);
140 repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int with_attr)
142 Pool *pool = repo->pool;
149 int last_found_pack = 0;
154 if (!repo->start || repo->start == repo->end)
155 repo->start = pool->nsolvables;
156 repo->end = pool->nsolvables;
158 attr = new_store (pool);
159 memset(&pd, 0, sizeof(pd));
171 if (linep - line + 16 > aline)
173 aline = linep - line;
174 line = realloc(line, aline + 512);
175 linep = line + aline;
178 if (!fgets(linep, aline - (linep - line), fp))
180 linep += strlen(linep);
181 if (linep == line || linep[-1] != '\n')
186 int isend = linep[-intag - 2] == '-' && linep[-1] == ':' && !strncmp(linep - 1 - intag, line + 1, intag) && (linep == line + 1 + intag + 1 + 1 + 1 + intag + 1 || linep[-intag - 3] == '\n');
187 if (cummulate && !isend)
192 if (cummulate && isend)
194 linep[-intag - 2] = 0;
195 if (linep[-intag - 3] == '\n')
196 linep[-intag - 3] = 0;
200 if (!cummulate && isend)
206 if (!cummulate && !isend)
207 linep = line + intag + 3;
211 if (!intag && line[0] == '+' && line[1] && line[1] != ':')
213 char *tagend = strchr(line, ':');
216 fprintf(stderr, "bad line: %s\n", line);
219 intag = tagend - (line + 1);
220 if (!strncmp (line, "+Des:", 5))
222 else if (!strncmp (line, "+Aut:", 5))
227 line[intag + 2] = ' ';
228 linep = line + intag + 3;
231 if (*line == '#' || !*line)
234 && (!strncmp(line, "=Pkg:", 5) || !strncmp(line, "=Pat:", 5)))
236 if (s && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
237 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
239 s->supplements = repo_fix_legacy(repo, s->provides, s->supplements);
243 if ((pack & PACK_BLOCK) == 0)
245 pool->solvables = realloc(pool->solvables, (pool->nsolvables + pack + PACK_BLOCK + 1) * sizeof(Solvable));
246 memset(pool->solvables + pool->nsolvables + pack, 0, (PACK_BLOCK + 1) * sizeof(Solvable));
248 s = pool->solvables + pool->nsolvables + pack;
250 last_found_pack = pack;
252 if (split(line + 5, sp, 5) != 4)
254 fprintf(stderr, "Bad line: %s\n", line);
258 s->name = str2id(pool, join(&pd, pd.kind, ":", sp[0]), 1);
260 s->name = str2id(pool, sp[0], 1);
261 s->evr = makeevr(pool, join(&pd, sp[1], "-", sp[2]));
262 s->arch = str2id(pool, sp[3], 1);
267 && (!strncmp(line, "=Pkg:", 5) || !strncmp(line, "=Pat:", 5)))
274 if (split(line + 5, sp, 5) != 4)
276 fprintf(stderr, "Bad line: %s\n", line);
281 name = str2id(pool, join(&pd, pd.kind, ":", sp[0]), 0);
283 name = str2id(pool, sp[0], 0);
284 evr = makeevr(pool, join(&pd, sp[1], "-", sp[2]));
285 arch = str2id(pool, sp[3], 0);
286 /* If we found neither the name of the arch at all in this repo
287 there's no chance of finding the exact solvable either. */
290 /* Now look for a solvable with the given name,evr,arch.
291 Our input is structured so, that the second set of =Pkg
292 lines comes in roughly the same order as the first set, so we
293 have a hint at where to start our search, namely were we found
295 for (n = 0, nn = last_found_pack; n < pack; n++, nn++)
299 s = pool->solvables + pool->nsolvables + nn;
300 if (s->name == name && s->evr == evr && s->arch == arch)
306 last_found_pack = nn;
309 /* If we have no current solvable to add to, ignore all further lines
310 for it. Probably invalid input data in the second set of
312 if (indesc >= 2 && !s)
314 fprintf (stderr, "Huh?\n");
317 if (!strncmp(line, "=Prv:", 5))
319 s->provides = adddep(pool, &pd, s->provides, line, 0, pd.kind);
322 if (!strncmp(line, "=Req:", 5))
324 s->requires = adddep(pool, &pd, s->requires, line, 1, pd.kind);
327 if (!strncmp(line, "=Prq:", 5))
330 s->requires = adddep(pool, &pd, s->requires, line, 0, 0);
332 s->requires = adddep(pool, &pd, s->requires, line, 2, 0);
335 if (!strncmp(line, "=Obs:", 5))
337 s->obsoletes = adddep(pool, &pd, s->obsoletes, line, 0, pd.kind);
340 if (!strncmp(line, "=Con:", 5))
342 s->conflicts = adddep(pool, &pd, s->conflicts, line, 0, pd.kind);
345 if (!strncmp(line, "=Rec:", 5))
347 s->recommends = adddep(pool, &pd, s->recommends, line, 0, pd.kind);
350 if (!strncmp(line, "=Sup:", 5))
352 s->supplements = adddep(pool, &pd, s->supplements, line, 0, pd.kind);
355 if (!strncmp(line, "=Enh:", 5))
357 s->enhances = adddep(pool, &pd, s->enhances, line, 0, pd.kind);
360 if (!strncmp(line, "=Sug:", 5))
362 s->suggests = adddep(pool, &pd, s->suggests, line, 0, pd.kind);
365 if (!strncmp(line, "=Fre:", 5))
367 s->freshens = adddep(pool, &pd, s->freshens, line, 0, pd.kind);
370 if (!strncmp(line, "=Prc:", 5))
372 s->recommends = adddep(pool, &pd, s->recommends, line, 0, 0);
375 if (!strncmp(line, "=Psg:", 5))
377 s->suggests = adddep(pool, &pd, s->suggests, line, 0, 0);
382 if (!strncmp(line, "=Grp:", 5))
384 ensure_entry (attr, last_found_pack);
385 add_attr_localids_id (attr, last_found_pack, str2nameid (attr, "group"), str2localid (attr, line + 6, 1));
388 if (!strncmp(line, "=Lic:", 5))
390 ensure_entry (attr, last_found_pack);
391 add_attr_localids_id (attr, last_found_pack, str2nameid (attr, "license"), str2localid (attr, line + 6, 1));
394 if (!strncmp(line, "=Kwd:", 5))
396 ensure_entry (attr, last_found_pack);
397 add_attr_localids_id (attr, last_found_pack, str2nameid (attr, "keywords"), str2localid (attr, line + 6, 1));
400 if (!strncmp(line, "=Aut:", 5))
402 ensure_entry (attr, last_found_pack);
403 add_attr_blob (attr, last_found_pack, str2nameid (attr, "authors"), line + 6, strlen (line + 6) + 1);
406 if (!strncmp(line, "=Sum:", 5))
408 ensure_entry (attr, last_found_pack);
409 add_attr_string (attr, last_found_pack, str2nameid (attr, "summary"), line + 6);
412 if (!strncmp(line, "=Des:", 5))
414 ensure_entry (attr, last_found_pack);
415 add_attr_blob (attr, last_found_pack, str2nameid (attr, "description"), line + 6, strlen (line + 6) + 1);
418 if (!strncmp(line, "=Ver:", 5))
425 if (s && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
426 s->provides = repo_addid_dep(repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
428 s->supplements = repo_fix_legacy(repo, s->provides, s->supplements);
430 pool->nsolvables += pack;
431 repo->nsolvables += pack;