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>][-l <locale>]\n"
63 " reads 'primary' from 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"
67 " -l <locale>: parse localization data for <locale>\n"
73 main(int argc, char **argv)
76 const char *attrname = 0;
77 const char *basefile = 0;
79 const char *locale = 0;
81 Pool *pool = pool_create();
82 Repo *repo = repo_create(pool, "<stdin>");
84 while ((c = getopt (argc, argv, "hkn:b:d:l:")) >= 0)
92 flags |= RPMMD_KINDS_SEPARATELY; /* do not use! */
116 l = strlen(dir) + 128;
117 fnp = sat_malloc(l+1);
118 snprintf(fnp, l, "%s/primary.xml.gz", dir);
119 if (!(fp = myfopen(fnp)))
124 repo_add_rpmmd(repo, fp, 0, flags);
126 snprintf(fnp, l, "%s/diskusagedata.xml.gz", dir);
127 if ((fp = myfopen(fnp)))
129 repo_add_rpmmd(repo, fp, 0, flags);
134 if (snprintf(fnp, l, "%s/translation-%s.xml.gz", dir, locale) >= l)
136 fprintf(stderr, "-l parameter too long\n");
139 while (!(fp = myfopen(fnp)))
141 fprintf(stderr, "not opened %s\n", fnp);
142 if (strlen(locale) > 2)
144 if (snprintf(fnp, l, "%s/translation-%.2s.xml.gz", dir, locale) >= l)
146 fprintf(stderr, "-l parameter too long\n");
149 if ((fp = myfopen(fnp)))
155 fprintf(stderr, "opened %s\n", fnp);
156 repo_add_rpmmd(repo, fp, 0, flags);
162 repo_add_rpmmd(repo, stdin, 0, flags);
163 tool_write(repo, basefile, attrname);