- move dataiterator declarations into a separate file
authorMichael Schroeder <mls@suse.de>
Tue, 17 Jan 2012 11:11:09 +0000 (12:11 +0100)
committerMichael Schroeder <mls@suse.de>
Tue, 17 Jan 2012 11:11:09 +0000 (12:11 +0100)
src/dataiterator.h [new file with mode: 0644]
src/repo.h
src/repodata.h

diff --git a/src/dataiterator.h b/src/dataiterator.h
new file mode 100644 (file)
index 0000000..0c1c849
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2007-2012, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/*
+ * dataiterator.h
+ * 
+ */
+
+#ifndef LIBSOLV_DATAITERATOR_H
+#define LIBSOLV_DATAITERATOR_H
+
+#include "pooltypes.h"
+#include "pool.h"
+
+struct _Repo;
+
+typedef struct _KeyValue {
+  Id id;
+  const char *str;
+  int num;
+  int num2;
+
+  int entry;   /* array entry, starts with 0 */
+  int eof;     /* last entry reached */
+
+  struct _KeyValue *parent;
+} KeyValue;
+
+/* search matcher flags */
+#define SEARCH_STRINGMASK              15
+#define SEARCH_STRING                  1
+#define SEARCH_STRINGSTART             2
+#define SEARCH_STRINGEND               3
+#define SEARCH_SUBSTRING               4
+#define SEARCH_GLOB                    5
+#define SEARCH_REGEX                   6
+#define SEARCH_ERROR                   15
+#define        SEARCH_NOCASE                   (1<<7)
+
+/* iterator control */
+#define        SEARCH_NO_STORAGE_SOLVABLE      (1<<8)
+#define SEARCH_SUB                     (1<<9)
+#define SEARCH_ARRAYSENTINEL           (1<<10)
+#define SEARCH_DISABLED_REPOS          (1<<11)
+#define SEARCH_COMPLETE_FILELIST       (1<<12)
+
+/* stringification flags */
+#define SEARCH_SKIP_KIND               (1<<16)
+/* By default we stringify just to the basename of a file because
+   the construction of the full filename is costly.  Specify this
+   flag if you want to match full filenames */
+#define SEARCH_FILES                   (1<<17)
+#define SEARCH_CHECKSUMS               (1<<18)
+
+/* dataiterator internal */
+#define SEARCH_THISSOLVID              (1<<31)
+
+typedef struct _Datamatcher {
+  int flags;
+  const char *match;
+  void *matchdata;
+  int error;
+} Datamatcher;
+
+typedef struct _Dataiterator
+{
+  int state;
+  int flags;
+
+  Pool *pool;
+  struct _Repo *repo;
+  struct _Repodata *data;
+
+  /* data pointers */
+  unsigned char *dp;
+  unsigned char *ddp;
+  Id *idp;
+  Id *keyp;
+
+  /* the result */
+  struct _Repokey *key;
+  KeyValue kv;
+
+  /* our matcher */
+  Datamatcher matcher;
+
+  /* iterators/filters */
+  Id keyname;
+  Id repodataid;
+  Id solvid;
+  Id repoid;
+
+  Id keynames[3 + 1];
+  int nkeynames;
+  int rootlevel;
+
+  /* recursion data */
+  struct di_parent {
+    KeyValue kv;
+    unsigned char *dp;
+    Id *keyp;
+  } parents[3];
+  int nparents;
+
+} Dataiterator;
+
+int  datamatcher_init(Datamatcher *ma, const char *match, int flags);
+void datamatcher_free(Datamatcher *ma);
+int  datamatcher_match(Datamatcher *ma, const char *str);
+
+/*
+ * Dataiterator
+ * 
+ * Iterator like interface to 'search' functionality
+ * 
+ * Dataiterator is per-pool, additional filters can be applied
+ * to limit the search domain. See dataiterator_init below.
+ * 
+ * Use these like:
+ *    Dataiterator di;
+ *    dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
+ *    while (dataiterator_step(&di))
+ *      dosomething(di.solvid, di.key, di.kv);
+ *    dataiterator_free(&di);
+ */
+
+/*
+ * Initialize dataiterator
+ * 
+ * di:      Pointer to Dataiterator to be initialized
+ * pool:    Search domain for the iterator
+ * repo:    if non-null, limit search to this repo
+ * solvid:  if non-null, limit search to this solvable
+ * keyname: if non-null, limit search to this keyname
+ * match:   if non-null, limit search to this match
+ */
+int  dataiterator_init(Dataiterator *di, Pool *pool, struct _Repo *repo, Id p, Id keyname, const char *match, int flags);
+void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
+void dataiterator_set_search(Dataiterator *di, struct _Repo *repo, Id p);
+void dataiterator_set_keyname(Dataiterator *di, Id keyname);
+int  dataiterator_set_match(Dataiterator *di, const char *match, int flags);
+
+void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
+void dataiterator_free(Dataiterator *di);
+int  dataiterator_step(Dataiterator *di);
+void dataiterator_setpos(Dataiterator *di);
+void dataiterator_setpos_parent(Dataiterator *di);
+int  dataiterator_match(Dataiterator *di, Datamatcher *ma);
+void dataiterator_skip_attribute(Dataiterator *di);
+void dataiterator_skip_solvable(Dataiterator *di);
+void dataiterator_skip_repo(Dataiterator *di);
+void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
+void dataiterator_jump_to_repo(Dataiterator *di, struct _Repo *repo);
+void dataiterator_entersub(Dataiterator *di);
+void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
+void dataiterator_seek(Dataiterator *di, int whence);
+
+#define DI_SEEK_STAY    (1 << 16)
+#define DI_SEEK_CHILD   1
+#define DI_SEEK_PARENT  2
+#define DI_SEEK_REWIND  3
+
+#endif /* LIBSOLV_DATAITERATOR_H */
index 7be3beb..b34c577 100644 (file)
@@ -16,6 +16,7 @@
 #include "pooltypes.h"
 #include "pool.h"
 #include "repodata.h"
+#include "dataiterator.h"
 #include "hash.h"
 
 
@@ -81,10 +82,6 @@ static inline Repodata *repo_id2repodata(Repo *repo, Id id)
   return id ? repo->repodata + id : 0;
 }
 
-#define FOR_REPO_SOLVABLES(r, p, s)                                            \
-  for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p)  \
-    if (s->repo == (r))
-
 
 /* those two functions are here because they need the Repo definition */
 
@@ -111,54 +108,11 @@ static inline int pool_installable(const Pool *pool, Solvable *s)
 }
 
 /* search callback values */
-
 #define SEARCH_NEXT_KEY         1
 #define SEARCH_NEXT_SOLVABLE    2
 #define SEARCH_STOP             3
 #define SEARCH_ENTERSUB                -1
 
-typedef struct _KeyValue {
-  Id id;
-  const char *str;
-  int num;
-  int num2;
-
-  int entry;   /* array entry, starts with 0 */
-  int eof;     /* last entry reached */
-
-  struct _KeyValue *parent;
-} KeyValue;
-
-/* search matcher flags */
-#define SEARCH_STRINGMASK              15
-#define SEARCH_STRING                  1
-#define SEARCH_STRINGSTART             2
-#define SEARCH_STRINGEND               3
-#define SEARCH_SUBSTRING               4
-#define SEARCH_GLOB                    5
-#define SEARCH_REGEX                   6
-#define SEARCH_ERROR                   15
-#define        SEARCH_NOCASE                   (1<<7)
-
-/* iterator control */
-#define        SEARCH_NO_STORAGE_SOLVABLE      (1<<8)
-#define SEARCH_SUB                     (1<<9)
-#define SEARCH_ARRAYSENTINEL           (1<<10)
-#define SEARCH_DISABLED_REPOS          (1<<11)
-#define SEARCH_COMPLETE_FILELIST       (1<<12)
-
-/* stringification flags */
-#define SEARCH_SKIP_KIND               (1<<16)
-/* By default we stringify just to the basename of a file because
-   the construction of the full filename is costly.  Specify this
-   flag if you want to match full filenames */
-#define SEARCH_FILES                   (1<<17)
-#define SEARCH_CHECKSUMS               (1<<18)
-
-/* dataiterator internal */
-#define SEARCH_THISSOLVID              (1<<31)
-
-
 /* standard flags used in the repo_add functions */
 #define REPO_REUSE_REPODATA            (1 << 0)
 #define REPO_NO_INTERNALIZE            (1 << 1)
@@ -183,112 +137,6 @@ int repo_lookup_void(Repo *repo, Id entry, Id keyname);
 const char *repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
 const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
 
-typedef struct _Datamatcher {
-  int flags;
-  const char *match;
-  void *matchdata;
-  int error;
-} Datamatcher;
-
-typedef struct _Dataiterator
-{
-  int state;
-  int flags;
-
-  Pool *pool;
-  Repo *repo;
-  Repodata *data;
-
-  /* data pointers */
-  unsigned char *dp;
-  unsigned char *ddp;
-  Id *idp;
-  Id *keyp;
-
-  /* the result */
-  Repokey *key;
-  KeyValue kv;
-
-  /* our matcher */
-  Datamatcher matcher;
-
-  /* iterators/filters */
-  Id keyname;
-  Id repodataid;
-  Id solvid;
-  Id repoid;
-
-  Id keynames[3 + 1];
-  int nkeynames;
-  int rootlevel;
-
-  /* recursion data */
-  struct di_parent {
-    KeyValue kv;
-    unsigned char *dp;
-    Id *keyp;
-  } parents[3];
-  int nparents;
-
-} Dataiterator;
-
-int  datamatcher_init(Datamatcher *ma, const char *match, int flags);
-void datamatcher_free(Datamatcher *ma);
-int  datamatcher_match(Datamatcher *ma, const char *str);
-
-/*
- * Dataiterator
- * 
- * Iterator like interface to 'search' functionality
- * 
- * Dataiterator is per-pool, additional filters can be applied
- * to limit the search domain. See dataiterator_init below.
- * 
- * Use these like:
- *    Dataiterator di;
- *    dataiterator_init(&di, repo->pool, repo, 0, 0, "bla", SEARCH_SUBSTRING);
- *    while (dataiterator_step(&di))
- *      dosomething(di.solvid, di.key, di.kv);
- *    dataiterator_free(&di);
- */
-
-/*
- * Initialize dataiterator
- * 
- * di:      Pointer to Dataiterator to be initialized
- * pool:    Search domain for the iterator
- * repo:    if non-null, limit search to this repo
- * solvid:  if non-null, limit search to this solvable
- * keyname: if non-null, limit search to this keyname
- * match:   if non-null, limit search to this match
- */
-int  dataiterator_init(Dataiterator *di, Pool *pool, Repo *repo, Id p, Id keyname, const char *match, int flags);
-void dataiterator_init_clone(Dataiterator *di, Dataiterator *from);
-void dataiterator_set_search(Dataiterator *di, Repo *repo, Id p);
-void dataiterator_set_keyname(Dataiterator *di, Id keyname);
-int  dataiterator_set_match(Dataiterator *di, const char *match, int flags);
-
-void dataiterator_prepend_keyname(Dataiterator *di, Id keyname);
-void dataiterator_free(Dataiterator *di);
-int  dataiterator_step(Dataiterator *di);
-void dataiterator_setpos(Dataiterator *di);
-void dataiterator_setpos_parent(Dataiterator *di);
-int  dataiterator_match(Dataiterator *di, Datamatcher *ma);
-void dataiterator_skip_attribute(Dataiterator *di);
-void dataiterator_skip_solvable(Dataiterator *di);
-void dataiterator_skip_repo(Dataiterator *di);
-void dataiterator_jump_to_solvid(Dataiterator *di, Id solvid);
-void dataiterator_jump_to_repo(Dataiterator *di, Repo *repo);
-void dataiterator_entersub(Dataiterator *di);
-void dataiterator_clonepos(Dataiterator *di, Dataiterator *from);
-void dataiterator_seek(Dataiterator *di, int whence);
-
-#define DI_SEEK_STAY    (1 << 16)
-#define DI_SEEK_CHILD   1
-#define DI_SEEK_PARENT  2
-#define DI_SEEK_REWIND  3
-
-
 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
 void repo_set_num(Repo *repo, Id p, Id keyname, unsigned int num);
 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
@@ -302,6 +150,11 @@ void repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker);
 void repo_internalize(Repo *repo);
 void repo_disable_paging(Repo *repo);
 
+/* iterator macros */
+#define FOR_REPO_SOLVABLES(r, p, s)                                            \
+  for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p)  \
+    if (s->repo == (r))
+
 #define FOR_REPODATAS(repo, rdid, data)        \
        for (rdid = 1, data = repo->repodata + rdid; rdid < repo->nrepodata; rdid++, data++)
 
index 1761550..ff23a6b 100644 (file)
@@ -29,9 +29,9 @@ struct _KeyValue;
 
 typedef struct _Repokey {
   Id name;
-  Id type;               /* REPOKEY_TYPE_xxx */
+  Id type;                     /* REPOKEY_TYPE_xxx */
   unsigned int size;
-  unsigned int storage; /* KEY_STORAGE_xxx */
+  unsigned int storage;                /* KEY_STORAGE_xxx */
 } Repokey;
 
 #define KEY_STORAGE_DROPPED             0