2 * Copyright (c) 2007, Novell Inc.
4 * This program is licensed under the BSD license, read LICENSE.BSD
5 * for further information
10 #include <sys/types.h>
21 #include "repo_rpmmd.h"
22 #include "common_write.h"
26 cookie_gzread(void *cookie, char *buf, size_t nbytes)
28 return gzread((gzFile *)cookie, buf, nbytes);
32 cookie_gzclose(void *cookie)
34 return gzclose((gzFile *)cookie);
38 myfopen(const char *fn)
40 cookie_io_functions_t cio;
46 suf = strrchr(fn, '.');
47 if (!suf || strcmp(suf, ".gz") != 0)
48 return fopen(fn, "r");
49 gzf = gzopen(fn, "r");
52 memset(&cio, 0, sizeof(cio));
53 cio.read = cookie_gzread;
54 cio.close = cookie_gzclose;
55 return fopencookie(gzf, "r", cio);
61 fprintf(stderr, "\nUsage:\n"
62 "rpmmd2solv [-a][-h][-k][-n <attrname>]\n"
63 " reads a 'rpmmd' repository from <stdin> and writes a .solv file to <stdout>\n"
64 " -h : print help & exit\n"
65 " -k : don't mix kinds (experimental!)\n"
66 " -n <name>: save attributes as <name>.attr\n"
72 main(int argc, char **argv)
75 const char *attrname = 0;
76 const char *basefile = 0;
80 Pool *pool = pool_create();
81 Repo *repo = repo_create(pool, "<stdin>");
83 while ((c = getopt (argc, argv, "hkn:b:d:")) >= 0)
91 flags |= RPMMD_KINDS_SEPARATELY; /* do not use! */
113 fnp = sat_malloc(l + 20);
114 sprintf(fnp, "%s/primary.xml.gz", dir);
115 if (!(fp = myfopen(fnp)))
120 repo_add_rpmmd(repo, fp, flags);
125 repo_add_rpmmd(repo, stdin, flags);
126 tool_write(repo, basefile, attrname);