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"
36 * join up to three strings into one
40 join(struct parsedata *pd, const char *s1, const char *s2, const char *s3)
54 pd->tmp = sat_realloc(pd->tmp, pd->tmpl);
77 makeevr(Pool *pool, char *s)
79 if (!strncmp(s, "0:", 2) && s[2])
81 return str2id(pool, s, 1);
93 * add single product to repo
98 repo_add_product(struct parsedata *pd, FILE *fp)
100 Repo *repo = pd->repo;
101 Pool *pool = repo->pool;
108 enum sections current_section = SECTION_UNKNOWN;
111 /* use last repodata */
112 data = repo->repodata + repo->nrepodata - 1;
114 data = repo_add_repodata(repo, 0);
116 line = sat_malloc(1024);
124 /* read line into big-enough buffer */
125 if (linep - line + 16 > aline)
127 aline = linep - line;
128 line = sat_realloc(line, aline + 512);
129 linep = line + aline;
132 if (!fgets(linep, aline - (linep - line), fp))
134 linep += strlen(linep);
135 if (linep == line || linep[-1] != '\n')
141 * Very trivial .ini parser
144 /* skip empty and comment lines */
151 /* sections must start at column 0 */
154 char *secp = linep+1;
156 endp = strchr(secp, ']');
159 fprintf(stderr, "Skipping unclosed section '%s'\n", line);
163 if (!strcmp(secp, "product"))
164 current_section = SECTION_PRODUCT;
167 fprintf(stderr, "Skipping unknown section '%s'\n", secp);
168 current_section = SECTION_UNKNOWN;
172 else if (current_section != SECTION_UNKNOWN)
177 /* split line into '<key> = <value>' */
178 while (*ptr && (*ptr == ' ' || *ptr == '\t'))
181 while (*ptr && !(*ptr == ' ' || *ptr == '\t' || *ptr == '='))
185 while (*ptr && !(*ptr == '='))
189 while (*ptr && (*ptr == ' ' || *ptr == '\t'))
192 while (*ptr && !(*ptr == ' ' || *ptr == '\t'))
196 if (current_section == SECTION_PRODUCT)
200 s = pool_id2solvable(pool, repo_add_solvable(repo));
201 repodata_extend(data, s - pool->solvables);
202 handle = repodata_get_handle(data, s - pool->solvables - repo->start);
204 if (!strcmp(key, "name"))
205 s->name = str2id(pool, join(pd, "product", ":", value), 1);
206 else if (!strcmp(key, "version"))
207 s->evr = makeevr(pool, value);
208 else if (!strcmp (key, "flavor"))
209 repo_set_str(repo, s - pool->solvables, PRODUCT_FLAVOR, value);
213 fprintf (stderr, "malformed line: %s\n", line);
218 fprintf(stderr, "No product solvable created !\n");
223 s->arch = ARCH_NOARCH;
224 if (s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
226 s->provides = repo_addid_dep(pd->repo, s->provides, rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
234 * read all .prod files from directory
235 * parse each one as a product
239 repo_add_products(Repo *repo, const char *proddir)
241 DIR *dir = opendir(proddir);
242 struct dirent *entry;
245 memset(&pd, 0, sizeof(pd));
254 while ((entry = readdir(dir)))
257 dot = strrchr( entry->d_name, '.' );
258 if (dot && strcmp(dot, ".prod") == 0)
260 char *fullpath = join(&pd, proddir, "/", entry->d_name);
261 FILE *fp = fopen(fullpath, "r");
267 repo_add_product(&pd, fp);