-static void
-writedeps(Repo *repo, FILE *fp, const char *tag, Id key, Solvable *s, Offset off)
-{
- Pool *pool = repo->pool;
- Id id, *dp, *prvdp;
- int tagwritten = 0;
- const char *idstr;
-
- if (!off)
- return;
- dp = repo->idarraydata + off;
- prvdp = 0;
- while ((id = *dp++) != 0)
- {
- if (key == SOLVABLE_REQUIRES && id == SOLVABLE_PREREQMARKER)
- {
- if (tagwritten)
- fprintf(fp, "-%s\n", tag);
- tagwritten = 0;
- tag = "Prq:";
- continue;
- }
- if (key == SOLVABLE_PROVIDES && id == SOLVABLE_FILEMARKER)
- {
- prvdp = dp;
- continue;
- }
- idstr = pool_dep2str(pool, id);
- if (ISRELDEP(id))
- {
- Reldep *rd = GETRELDEP(pool, id);
- if (key == SOLVABLE_CONFLICTS && rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_OTHERPROVIDERS)
- {
- if (!strncmp(idstr, "namespace:", 10))
- idstr += 10;
- }
- if (key == SOLVABLE_SUPPLEMENTS)
- {
- if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_FILESYSTEM)
- {
- if (!strncmp(idstr, "namespace:", 10))
- idstr += 10;
- }
- else if (rd->flags == REL_NAMESPACE && rd->name == NAMESPACE_MODALIAS)
- {
- if (!strncmp(idstr, "namespace:", 10))
- idstr += 10;
- }
- else if (rd->flags == REL_AND)
- {
- /* either packageand chain or modalias */
- idstr = 0;
- if (ISRELDEP(rd->evr))
- {
- Reldep *mrd = GETRELDEP(pool, rd->evr);
- if (mrd->flags == REL_NAMESPACE && mrd->name == NAMESPACE_MODALIAS)
- {
- idstr = pool_tmpjoin(pool, "modalias(", pool_dep2str(pool, rd->name), ":");
- idstr = pool_tmpappend(pool, idstr, pool_dep2str(pool, mrd->evr), ")");
- }
- else if (mrd->flags >= 8)
- continue;
- }
- if (!idstr)
- {
- /* must be and chain */
- idstr = pool_dep2str(pool, rd->evr);
- for (;;)
- {
- id = rd->name;
- if (!ISRELDEP(id))
- break;
- rd = GETRELDEP(pool, id);
- if (rd->flags != REL_AND)
- break;
- idstr = pool_tmpjoin(pool, pool_dep2str(pool, rd->evr), ":", idstr);
- }
- idstr = pool_tmpjoin(pool, pool_dep2str(pool, id), ":", idstr);
- idstr = pool_tmpjoin(pool, "packageand(", idstr, ")");
- }
- }
- else if (rd->flags >= 8)
- continue;
- }
- }
- if (!tagwritten)
- {
- fprintf(fp, "+%s\n", tag);
- tagwritten = 1;
- }
- fprintf(fp, "%s\n", idstr);
- }
- if (key == SOLVABLE_PROVIDES)
- {
- /* add the filelist */
- Dataiterator di;
- dataiterator_init(&di, pool, repo, s - pool->solvables, SOLVABLE_FILELIST, 0, 0);
- while (dataiterator_step(&di))
- {
- const char *s = repodata_dir2str(di.data, di.kv.id, di.kv.str);
- if (prvdp)
- {
- Id id = pool_str2id(pool, s, 0);
- if (id)
- {
- for (dp = prvdp; *dp; dp++)
- if (*dp == id)
- break;
- if (*dp)
- continue; /* already included */
- }
- }
- if (!tagwritten)
- {
- fprintf(fp, "+%s", tag);
- tagwritten = 1;
- }
- fprintf(fp, "%s\n", s);
- }
- }
- if (tagwritten)
- fprintf(fp, "-%s\n", tag);
-}
-
-int
-testcase_write_testtags(Repo *repo, FILE *fp)
-{
- Pool *pool = repo->pool;
- Solvable *s;
- Id p;
- const char *name;
- const char *evr;
- const char *arch;
- const char *release;
- const char *tmp;
- unsigned int ti;
-
- fprintf(fp, "=Ver: 2.0\n");
- FOR_REPO_SOLVABLES(repo, p, s)
- {
- name = pool_id2str(pool, s->name);
- evr = pool_id2str(pool, s->evr);
- arch = pool_id2str(pool, s->arch);
- release = strrchr(evr, '-');
- if (!release)
- release = evr + strlen(evr);
- fprintf(fp, "=Pkg: %s %.*s %s %s\n", name, (int)(release - evr), evr, *release && release[1] ? release + 1 : "-", arch);
- tmp = solvable_lookup_str(s, SOLVABLE_SUMMARY);
- if (tmp)
- fprintf(fp, "=Sum: %s\n", tmp);
- writedeps(repo, fp, "Req:", SOLVABLE_REQUIRES, s, s->requires);
- writedeps(repo, fp, "Prv:", SOLVABLE_PROVIDES, s, s->provides);
- writedeps(repo, fp, "Obs:", SOLVABLE_OBSOLETES, s, s->obsoletes);
- writedeps(repo, fp, "Con:", SOLVABLE_CONFLICTS, s, s->conflicts);
- writedeps(repo, fp, "Rec:", SOLVABLE_RECOMMENDS, s, s->recommends);
- writedeps(repo, fp, "Sup:", SOLVABLE_SUPPLEMENTS, s, s->supplements);
- writedeps(repo, fp, "Sug:", SOLVABLE_SUGGESTS, s, s->suggests);
- writedeps(repo, fp, "Enh:", SOLVABLE_ENHANCES, s, s->enhances);
- if (s->vendor)
- fprintf(fp, "=Vnd: %s\n", pool_id2str(pool, s->vendor));
- ti = solvable_lookup_num(s, SOLVABLE_BUILDTIME, 0);
- if (ti)
- fprintf(fp, "=Tim: %u\n", ti);
- }
- return 0;
-}
-
-static inline Offset
-adddep(Repo *repo, Offset olddeps, char *str, Id marker)
-{
- Id id = *str == '/' ? pool_str2id(repo->pool, str, 1) : testcase_str2dep(repo->pool, str);
- return repo_addid_dep(repo, olddeps, id, marker);
-}
-
-static void
-finish_solvable(Pool *pool, Repodata *data, Solvable *s, char *filelist, int nfilelist)
-{
- if (nfilelist)
- {
- int l;
- Id did;
- for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
- {
- char *p = strrchr(filelist + l, '/');
- if (!p)
- continue;
- *p++ = 0;
- did = repodata_str2dir(data, filelist + l, 1);
- p[-1] = '/';
- if (!did)
- did = repodata_str2dir(data, "/", 1);
- repodata_add_dirstr(data, s - pool->solvables, SOLVABLE_FILELIST, did, p);
- }
- }
- if (s->name && s->arch != ARCH_SRC && s->arch != ARCH_NOSRC)
- s->provides = repo_addid_dep(s->repo, s->provides, pool_rel2id(pool, s->name, s->evr, REL_EQ, 1), 0);
- s->supplements = repo_fix_supplements(s->repo, s->provides, s->supplements, 0);
- s->conflicts = repo_fix_conflicts(s->repo, s->conflicts);
-}
-
-/* stripped down version of susetags parser used for testcases */
-int
-testcase_add_testtags(Repo *repo, FILE *fp, int flags)
-{
- Pool *pool = repo->pool;
- char *line, *linep;
- int aline;
- int tag;
- Repodata *data;
- Solvable *s;
- char *sp[5];
- unsigned int t;
- int intag;
- char *filelist = 0;
- int afilelist = 0;
- int nfilelist = 0;
-
- data = repo_add_repodata(repo, flags);
- s = 0;
- intag = 0;
-
- aline = 1024;
- line = solv_malloc(aline);
- linep = line;
- for (;;)
- {
- if (linep - line + 16 > aline)
- {
- aline = linep - line;
- line = solv_realloc(line, aline + 512);
- linep = line + aline;
- aline += 512;
- }
- if (!fgets(linep, aline - (linep - line), fp))
- break;
- linep += strlen(linep);
- if (linep == line || linep[-1] != '\n')
- continue;
- linep[-1] = 0;
- linep = line + intag;
- if (intag)
- {
- if (line[intag] == '-' && !strncmp(line + 1, line + intag + 1, intag - 2))
- {
- intag = 0;
- linep = line;
- continue;
- }
- }
- else if (line[0] == '+' && line[1] && line[1] != ':')
- {
- char *tagend = strchr(line, ':');
- if (!tagend)
- continue;
- line[0] = '=';
- tagend[1] = ' ';
- intag = tagend + 2 - line;
- linep = line + intag;
- continue;
- }
- if (*line != '=' || !line[1] || !line[2] || !line[3] || line[4] != ':')
- continue;
- tag = line[1] << 16 | line[2] << 8 | line[3];
- switch(tag)
- {
- case 'P' << 16 | 'k' << 8 | 'g':
- if (s)
- finish_solvable(pool, data, s, filelist, nfilelist);
- nfilelist = 0;
- if (split(line + 5, sp, 5) != 4)
- break;
- s = pool_id2solvable(pool, repo_add_solvable(repo));
- s->name = pool_str2id(pool, sp[0], 1);
- /* join back version and release */
- if (sp[2] && !(sp[2][0] == '-' && !sp[2][1]))
- sp[2][-1] = '-';
- s->evr = makeevr(pool, sp[1]);
- s->arch = pool_str2id(pool, sp[3], 1);
- break;
- case 'S' << 16 | 'u' << 8 | 'm':
- repodata_set_str(data, s - pool->solvables, SOLVABLE_SUMMARY, line + 6);
- break;
- case 'V' << 16 | 'n' << 8 | 'd':
- s->vendor = pool_str2id(pool, line + 6, 1);
- break;
- case 'T' << 16 | 'i' << 8 | 'm':
- t = atoi(line + 6);
- if (t)
- repodata_set_num(data, s - pool->solvables, SOLVABLE_BUILDTIME, t);
- break;
- case 'R' << 16 | 'e' << 8 | 'q':
- s->requires = adddep(repo, s->requires, line + 6, -SOLVABLE_PREREQMARKER);
- break;
- case 'P' << 16 | 'r' << 8 | 'q':
- s->requires = adddep(repo, s->requires, line + 6, SOLVABLE_PREREQMARKER);
- break;
- case 'P' << 16 | 'r' << 8 | 'v':
- if (line[6] == '/')
- {
- int l = strlen(line + 6) + 1;
- if (nfilelist + l > afilelist)
- {
- afilelist = nfilelist + l + 512;
- filelist = solv_realloc(filelist, afilelist);
- }
- memcpy(filelist + nfilelist, line + 6, l);
- nfilelist += l;
- break;
- }
- if (nfilelist)
- {
- int l;
- for (l = 0; l < nfilelist; l += strlen(filelist + l) + 1)
- s->provides = repo_addid_dep(repo, s->provides, pool_str2id(pool, filelist + l, 1), 0);
- nfilelist = 0;
- }
- s->provides = adddep(repo, s->provides, line + 6, 0);
- break;
- case 'O' << 16 | 'b' << 8 | 's':
- s->obsoletes = adddep(repo, s->obsoletes, line + 6, 0);
- break;
- case 'C' << 16 | 'o' << 8 | 'n':
- s->conflicts = adddep(repo, s->conflicts, line + 6, 0);
- break;
- case 'R' << 16 | 'e' << 8 | 'c':
- s->recommends = adddep(repo, s->recommends, line + 6, 0);
- break;
- case 'S' << 16 | 'u' << 8 | 'p':
- s->supplements = adddep(repo, s->supplements, line + 6, 0);
- break;
- case 'S' << 16 | 'u' << 8 | 'g':
- s->suggests = adddep(repo, s->suggests, line + 6, 0);
- break;
- case 'E' << 16 | 'n' << 8 | 'h':
- s->enhances = adddep(repo, s->enhances, line + 6, 0);
- break;
- default:
- break;
- }
- }
- if (s)
- finish_solvable(pool, data, s, filelist, nfilelist);
- solv_free(line);
- solv_free(filelist);
- repodata_free_dircache(data);
- if (!(flags & REPO_NO_INTERNALIZE))
- repodata_internalize(data);
- return 0;
-}
-