return KEY_STORAGE_INCORE;
}
+/*
+ * Write <repo> to stdout
+ * If <attrname> is given, write attributes to <attrname>
+ */
+
int
-tool_write(Repo *repo, const char *basename, int separate)
+tool_write(Repo *repo, const char *basename, const char *attrname)
{
Pool *pool = repo->pool;
Repodatafile fileinfoa[1];
create_filter(pool);
memset (fileinfoa, 0, sizeof fileinfoa);
- if (separate)
+ if (attrname)
{
test_separate = 1;
fileinfo = fileinfoa;
- FILE *fp = fopen ("test.attr", "w");
+ FILE *fp = fopen (attrname, "w");
repo_write(repo, fp, keyfilter_attr, 0, fileinfo, 0);
fclose (fp);
- fileinfo->location = strdup ("test.attr");
+ fileinfo->location = strdup (attrname);
fileinfo++;
nsubfiles = fileinfo - fileinfoa;
#include "repo.h"
-int tool_write(Repo *repo, const char *basename, int separate);
+int tool_write(Repo *repo, const char *basename, const char *attrname);
#endif
#include <unistd.h>
#include <string.h>
+static char *attrname = 0;
+
#include "pool.h"
#include "repo_solv.h"
#if 0
static FILE *
loadcallback (Pool *pool, Repodata *data, void *vdata)
{
- FILE *fp;
+ FILE *fp = 0;
fprintf (stderr, "Loading SOLV file %s\n", data->location);
- fp = fopen ("test.attr", "r");
+ if (attrname)
+ {
+ fp = fopen (attrname, "r");
+ if (!fp)
+ perror(attrname);
+ }
return fp;
}
+
+static void
+usage( const char *err )
+{
+ if (err)
+ fprintf (stderr, "\n** Error:\n %s\n", err);
+ fprintf( stderr, "\nUsage:\n"
+ "dumpsolv [-a] [-n <attrname>] [<solvfile>]\n"
+ " -a read attributes.\n"
+ " If no attribute name (-n) is given,\n"
+ " it is deduced from the .solv name\n"
+ " by replacing '.solv' with '.attr'\n"
+ " If neither an attribute name nor a solvfile are given,\n"
+ " the attribute name defaults to 'test.attr'\n"
+ " -n <attrname> use <attrname> (evtl. suffixed by '.attr') for attributes\n"
+ );
+ exit(0);
+}
+
+
int main(int argc, char **argv)
{
Repo *repo;
Pool *pool;
int i, n;
Solvable *s;
+ const char *solvname = 0;
+
+ argv++;
+ argc--;
+ while (argc--)
+ {
+ const char *s = argv[0];
+ if (*s++ == '-')
+ while (*s)
+ switch (*s++)
+ {
+ case 'h': usage(NULL); break;
+ case 'a':
+ if (!attrname)
+ attrname = "";
+ break;
+ case 'n':
+ if (argc)
+ {
+ attrname = argv[1];
+ argv++;
+ argc--;
+ }
+ else
+ usage("argument required for '-n'");
+ break;
+ default : break;
+ }
+ else
+ {
+ solvname = argv[0];
+ if (freopen (solvname, "r", stdin) == 0)
+ {
+ perror(solvname);
+ exit(1);
+ }
+ break;
+ }
+ argv++;
+ }
- if (argc != 1)
+ if (attrname) /* attributes wanted */
{
- if (freopen(argv[1], "r", stdin) == 0)
+ if (*attrname == 0) /* no attrname given */
+ {
+ if (solvname) /* solvname given -> deduce attrname from it */
{
- perror(argv[1]);
- exit(1);
+ attrname = strdup (solvname);
+ char *dot = strrchr(attrname, '.');
+ if (dot && !strcmp(dot, ".solv")) /* if it ends in .solv, just keep the dot */
+ dot[1] = 0;
}
+ else
+ attrname = "test.attr"; /* default to "test.attr" */
+ }
+
+ /* ensure '.attr' suffix */
+ const char *dot = strrchr(attrname, '.');
+ if (!dot || strcmp(dot, ".attr"))
+ {
+ int len = strlen (attrname);
+ char *newname = (char *)malloc (len + 6); /* alloc for <attrname>+'.attr'+'\0' */
+ strcpy (newname, attrname);
+ strcpy (newname+len, ".attr");
+ attrname = newname;
+ }
}
+
pool = pool_create();
pool_setdebuglevel(pool, 1);
pool_setloadcallback(pool, loadcallback, 0);
*/
void
-repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int with_attr)
+repo_add_susetags(Repo *repo, FILE *fp, Id vendor, const char *attrname)
{
Pool *pool = repo->pool;
char *line, *linep;
struct parsedata pd;
Repodata *data = 0;
- if (with_attr)
+ if (attrname)
{
data = repo_add_repodata(repo);
init_attr_ids(pool);
indesc++;
continue;
}
- if (!with_attr)
+ if (!attrname)
continue;
switch (tag)
{
* for further information
*/
-extern void repo_add_susetags(Repo *repo, FILE *fp, Id vendor, int with_attr);
+/* read susetags file <fp> into <repo>
+ * if <attrname> given, write attributes as '<attrname>.attr'
+ */
+
+extern void repo_add_susetags(Repo *repo, FILE *fp, Id vendor, const char *attrname);
#include "common_write.h"
static void
-usage(void)
+usage(const char *err)
{
- fprintf(stderr, "Usage:\n"
+ if (err)
+ fprintf(stderr, "\n** Error:\n %s\n", err);
+ fprintf(stderr, "\nUsage:\n"
"susetags2solv [-a][-s][-c <content>][-h]\n"
" reads a 'susetags' repository from <stdin> and writes a .solv file to <stdout>\n"
" -a : with attributes\n"
- " -c : parse given contentfile (for product information)\n"
+ " -c <contenfile> : parse given contentfile (for product information)\n"
" -h : print help & exit\n"
- " -s : test separate\n"
+ " -n <name>: save attributes as <name>.attr\n"
);
+ exit(0);
}
int
main(int argc, char **argv)
{
- int with_attr = 0;
- int test_separate = 0;
const char *contentfile = 0;
+ const char *attrname = 0;
Id vendor = 0;
argv++;
argc--;
while (*s)
switch (*s++)
{
- case 'h': usage(); exit(0);
- case 'a': with_attr = 1; break;
- case 's': test_separate = 1; break;
+ case 'h': usage(NULL); break;
+ case 'a':
+ if (attrname == NULL)
+ attrname = "test.attr";
+ break;
+ case 'n':
+ if (argc)
+ {
+ attrname = argv[1];
+ argv++;
+ argc--;
+ }
+ else
+ usage("argument required for '-n'");
+ break;
case 'c':
if (argc)
{
argv++;
argc--;
}
+ else
+ usage("argument required for '-c'");
break;
default : break;
}
vendor = pool->solvables[repo->start].vendor;
fclose (fp);
}
- repo_add_susetags(repo, stdin, vendor, with_attr);
- tool_write(repo, 0, with_attr && test_separate);
+ if (attrname)
+ {
+ /* ensure '.attr' suffix */
+ const char *dot = strrchr(attrname, '.');
+ if (!dot || strcmp(dot, ".attr"))
+ {
+ int len = strlen (attrname);
+ char *newname = (char *)malloc (len + 6); /* alloc for <attrname>+'.attr'+'\0' */
+ strcpy (newname, attrname);
+ strcpy (newname+len, ".attr");
+ attrname = newname;
+ }
+ }
+ repo_add_susetags(repo, stdin, vendor, attrname);
+ tool_write(repo, 0, attrname);
pool_free(pool);
exit(0);
}