Mailinglist Archive: zypp-commit (545 mails)

< Previous Next >
[zypp-commit] r8678 - in /trunk/sat-solver/tools: common_write.c common_write.h dumpsolv.c repo_susetags.c repo_susetags.h susetags2solv.c
  • From: kkaempf@xxxxxxxxxxxxxxxx
  • Date: Thu, 14 Feb 2008 11:58:19 -0000
  • Message-id: <20080214115819.6FF28107492@xxxxxxxxxxxxxxxx>
Author: kkaempf
Date: Thu Feb 14 12:58:19 2008
New Revision: 8678

URL: http://svn.opensuse.org/viewcvs/zypp?rev=8678&view=rev
Log:
more flexibility in naming attribute files,
one can even have multiple ones in a single directory now ;-)

Modified:
trunk/sat-solver/tools/common_write.c
trunk/sat-solver/tools/common_write.h
trunk/sat-solver/tools/dumpsolv.c
trunk/sat-solver/tools/repo_susetags.c
trunk/sat-solver/tools/repo_susetags.h
trunk/sat-solver/tools/susetags2solv.c

Modified: trunk/sat-solver/tools/common_write.c
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/common_write.c?rev=8678&r1=8677&r2=8678&view=diff
==============================================================================
--- trunk/sat-solver/tools/common_write.c (original)
+++ trunk/sat-solver/tools/common_write.c Thu Feb 14 12:58:19 2008
@@ -70,8 +70,13 @@
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];
@@ -80,14 +85,14 @@

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;

Modified: trunk/sat-solver/tools/common_write.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/common_write.h?rev=8678&r1=8677&r2=8678&view=diff
==============================================================================
--- trunk/sat-solver/tools/common_write.h (original)
+++ trunk/sat-solver/tools/common_write.h Thu Feb 14 12:58:19 2008
@@ -10,6 +10,6 @@

#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

Modified: trunk/sat-solver/tools/dumpsolv.c
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/dumpsolv.c?rev=8678&r1=8677&r2=8678&view=diff
==============================================================================
--- trunk/sat-solver/tools/dumpsolv.c (original)
+++ trunk/sat-solver/tools/dumpsolv.c Thu Feb 14 12:58:19 2008
@@ -10,6 +10,8 @@
#include <unistd.h>
#include <string.h>

+static char *attrname = 0;
+
#include "pool.h"
#include "repo_solv.h"
#if 0
@@ -211,27 +213,111 @@
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);

Modified: trunk/sat-solver/tools/repo_susetags.c
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_susetags.c?rev=8678&r1=8677&r2=8678&view=diff
==============================================================================
--- trunk/sat-solver/tools/repo_susetags.c (original)
+++ trunk/sat-solver/tools/repo_susetags.c Thu Feb 14 12:58:19 2008
@@ -369,7 +369,7 @@
*/

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;
@@ -383,7 +383,7 @@
struct parsedata pd;
Repodata *data = 0;

- if (with_attr)
+ if (attrname)
{
data = repo_add_repodata(repo);
init_attr_ids(pool);
@@ -616,7 +616,7 @@
indesc++;
continue;
}
- if (!with_attr)
+ if (!attrname)
continue;
switch (tag)
{

Modified: trunk/sat-solver/tools/repo_susetags.h
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/repo_susetags.h?rev=8678&r1=8677&r2=8678&view=diff
==============================================================================
--- trunk/sat-solver/tools/repo_susetags.h (original)
+++ trunk/sat-solver/tools/repo_susetags.h Thu Feb 14 12:58:19 2008
@@ -5,4 +5,8 @@
* 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);

Modified: trunk/sat-solver/tools/susetags2solv.c
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/tools/susetags2solv.c?rev=8678&r1=8677&r2=8678&view=diff
==============================================================================
--- trunk/sat-solver/tools/susetags2solv.c (original)
+++ trunk/sat-solver/tools/susetags2solv.c Thu Feb 14 12:58:19 2008
@@ -19,24 +19,26 @@
#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--;
@@ -47,9 +49,21 @@
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)
{
@@ -57,6 +71,8 @@
argv++;
argc--;
}
+ else
+ usage("argument required for '-c'");
break;
default : break;
}
@@ -77,8 +93,21 @@
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);
}

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages