X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tools%2Frpmmd2solv.c;h=ad75025ea419abe36902c0c59d8d2c36061b30ff;hb=1aac48dff40ef592968a18058bad270da65ed847;hp=e5c2c84dbfc8699f457bc37708d66176b39fa26b;hpb=2397144294c496fe17c3a8b7ae2eaa45f2898b93;p=platform%2Fupstream%2Flibsolv.git diff --git a/tools/rpmmd2solv.c b/tools/rpmmd2solv.c index e5c2c84..ad75025 100644 --- a/tools/rpmmd2solv.c +++ b/tools/rpmmd2solv.c @@ -8,62 +8,28 @@ #define _GNU_SOURCE #include -#include -#include #include #include #include #include -#include #include "pool.h" #include "repo.h" #include "repo_rpmmd.h" +#ifdef SUSE +#include "repo_autopattern.h" +#endif #include "common_write.h" +#include "solv_xfopen.h" -static ssize_t -cookie_gzread(void *cookie, char *buf, size_t nbytes) -{ - return gzread((gzFile *)cookie, buf, nbytes); -} - -static int -cookie_gzclose(void *cookie) -{ - return gzclose((gzFile *)cookie); -} - -FILE * -myfopen(const char *fn) -{ - cookie_io_functions_t cio; - char *suf; - gzFile *gzf; - - if (!fn) - return 0; - suf = strrchr(fn, '.'); - if (!suf || strcmp(suf, ".gz") != 0) - return fopen(fn, "r"); - gzf = gzopen(fn, "r"); - if (!gzf) - return 0; - memset(&cio, 0, sizeof(cio)); - cio.read = cookie_gzread; - cio.close = cookie_gzclose; - return fopencookie(gzf, "r", cio); -} - static void usage(int status) { fprintf(stderr, "\nUsage:\n" - "rpmmd2solv [-a][-h][-n ][-l ]\n" + "rpmmd2solv [-h]\n" " reads 'primary' from a 'rpmmd' repository from and writes a .solv file to \n" " -h : print help & exit\n" - " -n : save attributes as .attr\n" - " -l : parse localization data for \n" ); exit(status); } @@ -71,92 +37,41 @@ usage(int status) int main(int argc, char **argv) { - int c, flags = 0; - const char *attrname = 0; - const char *basefile = 0; - const char *dir = 0; - const char *locale = 0; + int c; +#ifdef SUSE + int add_auto = 0; +#endif Pool *pool = pool_create(); Repo *repo = repo_create(pool, ""); - while ((c = getopt (argc, argv, "hn:b:d:l:")) >= 0) + while ((c = getopt (argc, argv, "hX")) >= 0) { - switch(c) + switch (c) { case 'h': usage(0); break; - case 'n': - attrname = optarg; - break; - case 'b': - basefile = optarg; - break; - case 'd': - dir = optarg; - break; - case 'l': - locale = optarg; + case 'X': +#ifdef SUSE + add_auto = 1; +#endif break; default: usage(1); break; } } - if (dir) + if (repo_add_rpmmd(repo, stdin, 0, 0)) { - FILE *fp; - int l; - char *fnp; - l = strlen(dir) + 128; - fnp = sat_malloc(l+1); - snprintf(fnp, l, "%s/primary.xml.gz", dir); - if (!(fp = myfopen(fnp))) - { - perror(fnp); - exit(1); - } - repo_add_rpmmd(repo, fp, 0, flags); - fclose(fp); - snprintf(fnp, l, "%s/diskusagedata.xml.gz", dir); - if ((fp = myfopen(fnp))) - { - repo_add_rpmmd(repo, fp, 0, flags); - fclose(fp); - } - if (locale) - { - if (snprintf(fnp, l, "%s/translation-%s.xml.gz", dir, locale) >= l) - { - fprintf(stderr, "-l parameter too long\n"); - exit(1); - } - while (!(fp = myfopen(fnp))) - { - fprintf(stderr, "not opened %s\n", fnp); - if (strlen(locale) > 2) - { - if (snprintf(fnp, l, "%s/translation-%.2s.xml.gz", dir, locale) >= l) - { - fprintf(stderr, "-l parameter too long\n"); - exit(1); - } - if ((fp = myfopen(fnp))) - break; - } - perror(fnp); - exit(1); - } - fprintf(stderr, "opened %s\n", fnp); - repo_add_rpmmd(repo, fp, 0, flags); - fclose(fp); - } - sat_free(fnp); + fprintf(stderr, "rpmmd2solv: %s\n", pool_errstr(pool)); + exit(1); } - else - repo_add_rpmmd(repo, stdin, 0, flags); - tool_write(repo, basefile, attrname); +#ifdef SUSE + if (add_auto) + repo_add_autopattern(repo, 0); +#endif + tool_write(repo, stdout); pool_free(pool); exit(0); }