aboutsummaryrefslogtreecommitdiffstats
path: root/src/reader.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-02-21 03:12:06 +0000
committerDavid Robillard <d@drobilla.net>2012-02-21 03:12:06 +0000
commit5121ecc53618dcca1510eb2af85ea57699cff071 (patch)
tree45de5f9031520f19725e7dafc688ce75b00f951a /src/reader.c
parent8893d8fcc15f2c8f85527ccf3f68dceaed8b2566 (diff)
downloadserd-5121ecc53618dcca1510eb2af85ea57699cff071.tar.gz
serd-5121ecc53618dcca1510eb2af85ea57699cff071.tar.bz2
serd-5121ecc53618dcca1510eb2af85ea57699cff071.zip
Make -p actually work as advertised.
git-svn-id: http://svn.drobilla.net/serd/trunk@319 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/reader.c')
-rw-r--r--src/reader.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/reader.c b/src/reader.c
index 230502ab..0a6b3467 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -30,6 +30,8 @@
#define TRY_THROW(exp) if (!(exp)) goto except;
#define TRY_RET(exp) if (!(exp)) return 0;
+#define MAX_ID_SIZE (5 + 10 + 1) /* "genid" + UINT32_MAX + \0 */
+
#ifdef SERD_STACK_CHECK
# define SERD_STACK_ASSERT_TOP(reader, ref) \
assert(ref == reader->allocs[reader->n_allocs - 1]);
@@ -940,7 +942,9 @@ read_nodeID(SerdReader* reader)
{
eat_byte_safe(reader, '_');
eat_byte_check(reader, ':');
- Ref ref = push_node(reader, SERD_BLANK, "", 0);
+ Ref ref = push_node(reader, SERD_BLANK,
+ reader->bprefix ? (char*)reader->bprefix : "",
+ reader->bprefix_len);
if (!read_name(reader, ref)) {
return error(reader, "illegal character at start of name\n");
}
@@ -953,26 +957,19 @@ read_nodeID(SerdReader* reader)
return ref;
}
-static size_t
-max_id_size(SerdReader* reader)
-{
- return reader->bprefix_len + 5 + 10 + 1; // "genid" UINT32_MAX \0
-}
-
static void
set_blank_id(SerdReader* reader, Ref ref, size_t buf_size)
{
SerdNode* node = deref(reader, ref);
node->n_bytes = node->n_chars = snprintf(
- (char*)node->buf, buf_size, "%sgenid%u",
- reader->bprefix ? (char*)reader->bprefix : "", reader->next_id++);
+ (char*)node->buf, buf_size, "genid%u", reader->next_id++);
}
static Ref
blank_id(SerdReader* reader)
{
- Ref ref = push_node_padded(reader, max_id_size(reader), SERD_BLANK, "", 0);
- set_blank_id(reader, ref, max_id_size(reader));
+ Ref ref = push_node_padded(reader, MAX_ID_SIZE, SERD_BLANK, "", 0);
+ set_blank_id(reader, ref, MAX_ID_SIZE);
return ref;
}
@@ -1170,11 +1167,10 @@ read_collection(SerdReader* reader, ReadContext ctx, Ref* dest)
/* The order of node allocation here is necessarily not in stack order,
so we create two nodes and recycle them throughout. */
- size_t id_size = max_id_size(reader);
- Ref n1 = push_node_padded(reader, id_size, SERD_BLANK, "", 0);
- Ref n2 = 0;
- Ref node = n1;
- Ref rest = 0;
+ Ref n1 = push_node_padded(reader, MAX_ID_SIZE, SERD_BLANK, "", 0);
+ Ref n2 = 0;
+ Ref node = n1;
+ Ref rest = 0;
ctx.subject = *dest;
while (!(end = peek_delim(reader, ')'))) {
@@ -1190,7 +1186,7 @@ read_collection(SerdReader* reader, ReadContext ctx, Ref* dest)
if (!rest) {
rest = n2 = blank_id(reader); // First pass, push a new node
} else {
- set_blank_id(reader, rest, id_size);
+ set_blank_id(reader, rest, MAX_ID_SIZE);
}
}