4 * Parses all files below 'proddir'
5 * See http://en.opensuse.org/Product_Management/Code11
8 * Copyright (c) 2007, Novell Inc.
10 * This program is licensed under the BSD license, read LICENSE.BSD
11 * for further information
14 #include <sys/types.h>
26 #include "repo_content.h"
38 * split l into m parts, store to sp[]
43 split(char *l, char **sp, int m)
48 while (*l == ' ' || *l == '\t')
55 while (*l && !(*l == ' ' || *l == '\t'))
66 makeevr(Pool *pool, char *s)
68 if (!strncmp(s, "0:", 2) && s[2])
70 return str2id(pool, s, 1);
74 * dependency relations
77 static char *flagtab[] = {
88 * join up to three strings into one
92 join(struct parsedata *pd, const char *s1, const char *s2, const char *s3)
106 pd->tmp = sat_realloc(pd->tmp, pd->tmpl);
130 * add dependency to pool
134 adddep(Pool *pool, struct parsedata *pd, unsigned int olddeps, char *line, Id marker)
143 /* Name [relop evr] [rest] --> 1, 2, 3 or 4 fields. */
146 words += split(line, sp + words, 4 - words);
149 /* Hack, as the content file adds 'package:' for package
150 dependencies sometimes. */
151 if (!strncmp (sp[0], "package:", 8))
153 id = str2id(pool, sp[0], 1);
154 if (words >= 3 && strpbrk (sp[1], "<>="))
156 evrid = makeevr(pool, sp[2]);
157 for (flags = 0; flags < 6; flags++)
158 if (!strcmp(sp[1], flagtab[flags]))
162 fprintf(stderr, "Unknown relation '%s'\n", sp[1]);
165 id = rel2id(pool, id, evrid, flags + 1, 1);
166 /* Consume three words, there's nothing to move to front. */
174 /* Consume one word. If we had more move them to front. */
176 for (j = 0; j < words; j++)
179 line = sp[2], words = 2;
181 olddeps = repo_addid_dep(pd->repo, olddeps, id, marker);
182 if (! ( line || words > 0 ) )
190 * split value and add to pool
194 add_multiple_strings(Repodata *data, Id handle, Id name, char *value)
199 int words = split(value, sp, 2);
202 repodata_add_poolstr_array(data, handle, name, sp[0]);
211 * add single product to repo
216 repo_add_product(struct parsedata *pd, FILE *fp)
219 Pool *pool = pd->repo->pool;
222 Solvable *s, *firsts = 0;
225 line = sat_malloc(1024);
233 /* char *fields[2]; */
235 /* read line into big-enough buffer */
236 if (linep - line + 16 > aline)
238 aline = linep - line;
239 line = sat_realloc(line, aline + 512);
240 linep = line + aline;
243 if (!fgets(linep, aline - (linep - line), fp))
245 linep += strlen(linep);
246 if (linep == line || linep[-1] != '\n')
250 /* expect "key value" lines */
251 if (split (line, fields, 2) == 2)
253 char *key = fields[0];
254 char *value = fields[1];
257 fprintf (stderr, "malformed line: %s\n", line);
262 fprintf(stderr, "No product solvable created !\n");
267 s->arch = ARCH_NOARCH;
268 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
270 s->provides = repo_addid_dep(pd->repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
279 * read all .prod files from directory
280 * parse each one as a product
284 repo_add_products(Repo *repo, const char *proddir)
286 DIR *dir = opendir(proddir);
287 struct dirent *entry;
291 memset(&pd, 0, sizeof(pd));
293 /* use last repodata */
294 data = repo->repodata + repo->nrepodata - 1;
296 data = repo_add_repodata(repo, 0);
306 while ((entry = readdir(dir)))
309 dot = strrchr( entry->d_name, '.' );
310 if (dot && strcmp(dot, ".prod") == 0)
312 char *fullpath = join(&pd, proddir, "/", entry->d_name);
313 FILE *fp = fopen(fullpath, "r");
319 repo_add_product(&pd, fp);