#define LOCALID_NULL 0
#define LOCALID_EMPTY 1
-static Id add_key (Attrstore *s, NameId name, unsigned type, unsigned size);
+static Id add_key (Attrstore *s, Id name, unsigned type, unsigned size);
Attrstore *
new_store (Pool *pool)
};
Attrstore *s = calloc (1, sizeof (Attrstore));
s->pool = pool;
- s->nameids = calloc (128, sizeof (s->nameids[0]));
- s->num_nameids = 2;
- s->nameids[0] = 0;
- s->nameids[1] = 1;
-
stringpool_init (&s->ss, predef_strings);
add_key (s, 0, 0, 0);
return s->ss.stringspace + s->ss.strings[id];
}
-static NameId
-id2nameid (Attrstore *s, Id id)
-{
- unsigned int i;
- for (i = 0; i < s->num_nameids; i++)
- if (s->nameids[i] == id)
- return i;
- if (s->num_nameids >= (1 << NAME_WIDTH))
- {
- fprintf (stderr, "Too many attribute names\n");
- exit (1);
- }
- if ((s->num_nameids & 127) == 0)
- s->nameids = realloc (s->nameids, ((s->num_nameids+128) * sizeof (s->nameids[0])));
- s->nameids[s->num_nameids++] = id;
- return s->num_nameids - 1;
-}
-
-NameId
-str2nameid (Attrstore *s, const char *str)
-{
- return id2nameid (s, str2id (s->pool, str, 1));
-}
-
void
ensure_entry (Attrstore *s, unsigned int entry)
{
}
static LongNV *
-find_attr (Attrstore *s, unsigned int entry, NameId name)
+find_attr (Attrstore *s, unsigned int entry, Id name)
{
LongNV *nv;
if (entry >= s->entries)
return 0;
- if (name >= s->num_nameids)
- return 0;
nv = s->attrs[entry];
if (nv)
{
}
void
-add_attr_int (Attrstore *s, unsigned int entry, NameId name, unsigned int val)
+add_attr_int (Attrstore *s, unsigned int entry, Id name, unsigned int val)
{
LongNV nv;
nv.key = add_key (s, name, ATTR_INT, 0);
}
static void
-add_attr_chunk (Attrstore *s, unsigned int entry, NameId name, unsigned int ofs, unsigned int len)
+add_attr_chunk (Attrstore *s, unsigned int entry, Id name, unsigned int ofs, unsigned int len)
{
LongNV nv;
nv.key = add_key (s, name, ATTR_CHUNK, 0);
}
void
-add_attr_blob (Attrstore *s, unsigned int entry, NameId name, const void *ptr, unsigned int len)
+add_attr_blob (Attrstore *s, unsigned int entry, Id name, const void *ptr, unsigned int len)
{
if (((s->blob_next_free + BLOB_BLOCK) & ~BLOB_BLOCK)
!= ((s->blob_next_free + len + BLOB_BLOCK) & ~BLOB_BLOCK))
}
void
-add_attr_string (Attrstore *s, unsigned int entry, NameId name, const char *val)
+add_attr_string (Attrstore *s, unsigned int entry, Id name, const char *val)
{
LongNV nv;
nv.key = add_key (s, name, ATTR_STRING, 0);
}
void
-add_attr_intlist_int (Attrstore *s, unsigned int entry, NameId name, int val)
+add_attr_intlist_int (Attrstore *s, unsigned int entry, Id name, int val)
{
LongNV *nv = find_attr (s, entry, name);
if (val == 0)
}
void
-add_attr_localids_id (Attrstore *s, unsigned int entry, NameId name, LocalId id)
+add_attr_localids_id (Attrstore *s, unsigned int entry, Id name, LocalId id)
{
LongNV *nv = find_attr (s, entry, name);
if (nv)
}
static Id
-add_key (Attrstore *s, NameId name, unsigned type, unsigned size)
+add_key (Attrstore *s, Id name, unsigned type, unsigned size)
{
unsigned i;
for (i = 0; i < s->nkeys; i++)
attr_store_pack (s);
+ /* Transform our attribute names (pool string IDs) into local IDs. */
+ for (i = 1; i < s->nkeys; i++)
+ s->keys[i].name = str2localid (s, id2str (s->pool, s->keys[i].name), 1);
+
/* write file header */
write_u32(fp, 'S' << 24 | 'O' << 16 | 'L' << 8 | 'V');
write_u32(fp, SOLV_VERSION_2);
write_id (fp, s->keys[i].name);
write_id (fp, s->keys[i].type);
write_id (fp, s->keys[i].size);
+
+ /* Also transform back the names (now local IDs) into pool IDs,
+ so we can use the pool also after writing. */
+ s->keys[i].name = str2id (s->pool, localid2str (s, s->keys[i].name), 0);
}
write_id (fp, s->szschemata - 1);
exit (1);
}
- write_u32 (fp, s->num_nameids);
- for (i = 2; i < s->num_nameids; i++)
- {
- const char *str = id2str (s->pool, s->nameids[i]);
- if (fwrite(str, strlen(str) + 1, 1, fp) != 1)
- {
- perror("write error");
- exit(1);
- }
- }
-
write_pages (fp, s);
}
return x;
}
-static unsigned int
-read_u8(FILE *fp)
-{
- int c;
- c = getc(fp);
- if (c == EOF)
- {
- fprintf(stderr, "unexpected EOF\n");
- exit(1);
- }
- return c;
-}
-
static Id
read_id(FILE *fp, Id max)
{
unsigned i;
unsigned local_ssize;
unsigned nstrings, nschemata;
- char *buf;
- size_t buflen;
Attrstore *s = new_store (pool);
if (read_u32(fp) != ('S' << 24 | 'O' << 16 | 'L' << 8 | 'V'))
/* s->keys[0] is initialized in new_store. */
for (i = 1; i < s->nkeys; i++)
{
- s->keys[i].name = read_id (fp, 0 /*s->num_nameids*/);
+ s->keys[i].name = read_id (fp, nstrings);
s->keys[i].type = read_id (fp, ATTR_TYPE_MAX + 1);
s->keys[i].size = read_id (fp, 0);
+
+ /* Globalize the attribute names (they are local IDs right now). */
+ s->keys[i].name = str2id (s->pool, localid2str (s, s->keys[i].name), 1);
}
s->szschemata = 1 + read_id (fp, 0);
exit (1);
}
- s->num_nameids = read_u32 (fp);
-
- buflen = 128;
- buf = malloc (buflen);
-
- s->nameids = realloc (s->nameids, (((s->num_nameids+127) & ~127) * sizeof (s->nameids[0])));
- for (i = 2; i < s->num_nameids; i++)
- {
- size_t p = 0;
- while (1)
- {
- int c = read_u8 (fp);
- if (p == buflen)
- {
- buflen += 128;
- buf = realloc (buf, buflen);
- }
- buf[p++] = c;
- if (!c)
- break;
- }
- s->nameids[i] = str2id (s->pool, buf, 1);
- }
-
read_or_setup_pages (fp, s);
s->packed = 1;
- free (buf);
-
return s;
}
void
-attr_store_search_s (Attrstore *s, const char *pattern, int flags, NameId name, cb_attr_search_s cb)
+attr_store_search_s (Attrstore *s, const char *pattern, int flags, Id name, cb_attr_search_s cb)
{
unsigned int i;
attr_iterator ai;
break;
}
if (match)
- cb (s, i, s->nameids[ai.name], str);
+ cb (s, i, ai.name, str);
if (ai.type != ATTR_LOCALIDS)
break;
Id val;
unsigned int id2 = new_entry (s);
unsigned int id3 = new_entry (s);
unsigned int id4 = new_entry (s);
- add_attr_int (s, id1, str2nameid (s, "name1"), 42);
- add_attr_chunk (s, id1, str2nameid (s, "name2"), 9876, 1024);
- add_attr_string (s, id1, str2nameid (s, "name3"), "hallo");
- add_attr_int (s, id1, str2nameid (s, "name1"), 43);
- add_attr_intlist_int (s, id1, str2nameid (s, "intlist1"), 3);
- add_attr_intlist_int (s, id1, str2nameid (s, "intlist1"), 14);
- add_attr_intlist_int (s, id1, str2nameid (s, "intlist1"), 1);
- add_attr_intlist_int (s, id1, str2nameid (s, "intlist1"), 59);
- add_attr_localids_id (s, id1, str2nameid (s, "l_ids1"), str2localid (s, "one", 1));
- add_attr_localids_id (s, id1, str2nameid (s, "l_ids1"), str2localid (s, "two", 1));
- add_attr_localids_id (s, id1, str2nameid (s, "l_ids1"), str2localid (s, "three", 1));
- add_attr_localids_id (s, id1, str2nameid (s, "l_ids2"), str2localid (s, "three", 1));
- add_attr_localids_id (s, id1, str2nameid (s, "l_ids2"), str2localid (s, "two", 1));
- add_attr_localids_id (s, id1, str2nameid (s, "l_ids2"), str2localid (s, "one", 1));
+ add_attr_int (s, id1, str2id (s, "name1", 1), 42);
+ add_attr_chunk (s, id1, str2id (s->pool, "name2", 1), 9876, 1024);
+ add_attr_string (s, id1, str2id (s->pool, "name3", 1), "hallo");
+ add_attr_int (s, id1, str2id (s->pool, "name1", 1), 43);
+ add_attr_intlist_int (s, id1, str2id (s->pool, "intlist1", 1), 3);
+ add_attr_intlist_int (s, id1, str2id (s->pool, "intlist1", 1), 14);
+ add_attr_intlist_int (s, id1, str2id (s->pool, "intlist1", 1), 1);
+ add_attr_intlist_int (s, id1, str2id (s->pool, "intlist1", 1), 59);
+ add_attr_localids_id (s, id1, str2id (s->pool, "l_ids1", 1), str2localid (s, "one", 1));
+ add_attr_localids_id (s, id1, str2id (s->pool, "l_ids1", 1), str2localid (s, "two", 1));
+ add_attr_localids_id (s, id1, str2id (s->pool, "l_ids1", 1), str2localid (s, "three", 1));
+ add_attr_localids_id (s, id1, str2id (s->pool, "l_ids2", 1), str2localid (s, "three", 1));
+ add_attr_localids_id (s, id1, str2id (s->pool, "l_ids2", 1), str2localid (s, "two", 1));
+ add_attr_localids_id (s, id1, str2id (s->pool, "l_ids2", 1), str2localid (s, "one", 1));
write_attr_store (stdout, s);
return 0;
}
if (!strncmp(line, "=Grp:", 5))
{
ensure_entry (attr, last_found_pack);
- add_attr_localids_id (attr, last_found_pack, str2nameid (attr, "group"), str2localid (attr, line + 6, 1));
+ add_attr_localids_id (attr, last_found_pack, str2id (pool, "group", 1), str2localid (attr, line + 6, 1));
continue;
}
if (!strncmp(line, "=Lic:", 5))
{
ensure_entry (attr, last_found_pack);
- add_attr_localids_id (attr, last_found_pack, str2nameid (attr, "license"), str2localid (attr, line + 6, 1));
+ add_attr_localids_id (attr, last_found_pack, str2id (pool, "license", 1), str2localid (attr, line + 6, 1));
continue;
}
if (!strncmp(line, "=Kwd:", 5))
{
ensure_entry (attr, last_found_pack);
- add_attr_localids_id (attr, last_found_pack, str2nameid (attr, "keywords"), str2localid (attr, line + 6, 1));
+ add_attr_localids_id (attr, last_found_pack, str2id (pool, "keywords", 1), str2localid (attr, line + 6, 1));
continue;
}
if (!strncmp(line, "=Aut:", 5))
{
ensure_entry (attr, last_found_pack);
- add_attr_blob (attr, last_found_pack, str2nameid (attr, "authors"), line + 6, strlen (line + 6) + 1);
+ add_attr_blob (attr, last_found_pack, str2id (pool, "authors", 1), line + 6, strlen (line + 6) + 1);
continue;
}
if (!strncmp(line, "=Sum:", 5))
{
ensure_entry (attr, last_found_pack);
- add_attr_string (attr, last_found_pack, str2nameid (attr, "summary"), line + 6);
+ add_attr_string (attr, last_found_pack, str2id (pool, "summary", 1), line + 6);
continue;
}
if (!strncmp(line, "=Des:", 5))
{
ensure_entry (attr, last_found_pack);
- add_attr_blob (attr, last_found_pack, str2nameid (attr, "description"), line + 6, strlen (line + 6) + 1);
+ add_attr_blob (attr, last_found_pack, str2id (pool, "description", 1), line + 6, strlen (line + 6) + 1);
continue;
}
if (!strncmp(line, "=Ver:", 5))