From triplesoup-commits-return-32-apmail-incubator-triplesoup-commits-archive=incubator.apache.org@incubator.apache.org Wed Feb 21 21:57:13 2007 Return-Path: Delivered-To: apmail-incubator-triplesoup-commits-archive@locus.apache.org Received: (qmail 21296 invoked from network); 21 Feb 2007 21:57:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Feb 2007 21:57:10 -0000 Received: (qmail 70053 invoked by uid 500); 21 Feb 2007 21:57:18 -0000 Delivered-To: apmail-incubator-triplesoup-commits-archive@incubator.apache.org Received: (qmail 70011 invoked by uid 500); 21 Feb 2007 21:57:18 -0000 Mailing-List: contact triplesoup-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: triplesoup-dev@incubator.apache.org Delivered-To: mailing list triplesoup-commits@incubator.apache.org Received: (qmail 70001 invoked by uid 99); 21 Feb 2007 21:57:18 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Feb 2007 13:57:18 -0800 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Feb 2007 13:57:06 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 7B7911A9823; Wed, 21 Feb 2007 13:56:46 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r510255 [3/3] - in /incubator/triplesoup/donations/TRIPLES-2-libb: ./ redland-integration/ src/ tests/ utils/ Date: Wed, 21 Feb 2007 21:56:45 -0000 To: triplesoup-commits@incubator.apache.org From: leosimons@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070221215646.7B7911A9823@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/triplesoup/donations/TRIPLES-2-libb/src/btriple.c URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/src/btriple.c?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/src/btriple.c (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/src/btriple.c Wed Feb 21 13:56:43 2007 @@ -0,0 +1,356 @@ +/* (c) 2007 Satis Superque Merce B.V. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + */ + +#include + +b_error_t +b_triple_check (b_triple_t * triple) +{ + + B_LOG1 ("b_triple_check: %p", triple); + + if (!triple) + return B_ERROR_DATA; + + if (!triple->subject_uri && !triple->subject_bnode) + return B_ERROR_DATA; + + if (!triple->property) + return B_ERROR_DATA; + + if (!triple->object_uri && !triple->object_bnode && !triple->object_literal) + return B_ERROR_DATA; + + return B_OK; +} + +/** + * b_triple_new_incomplete: + * @triple: The return pointer for the new b_triple_t data struct. + * @subject_uri: The subject URI. It can be NULL if the subject_object is not + * NULL. + * @subject_uri_len: The length of the subject_uri. Can be 0. + * @subject_bnode: The subject BNODE. + * @subject_bnode_len: The length of the subject_bnode. Can be 0. + * @property: The property of this triple. + * @property_len: The length of the property. Can be 0. + * @object_uri: The object as URI. It can be NULL if the triple has not a URI + * object. + * @object_uri_len: The length of the URI object. Can be 0. + * @object_bnode: The object as BNODE. It can be NULL if the triple has not a + * BNODE object. + * @object_bnode_len: The length of the BNODE object. Can be 0. + * @object_literal: The object as Literal. It can be NULL if the triple has not + * a Literal object. + * @object_literal_len: The length of the Literal Object. Can be 0. + * @context: The context. Can be NULL. + * @context_len: The Context Length. + * @datatype: The datatype for this Object Literal. It can be NULL. + * @datatype_len: The length of the datatype. + * @lang: The lang of this Object Literal. + * @lang_len: The length of the lang. + * @returns: The error code. + * + * Creates a new triples. It will not checked so you can create a incomplete + * triple for the iterator. This triple must be destroy with + * b_triple_destroy(). + **/ +b_error_t +b_triple_new_incomplete (b_triple_t ** ret, unsigned char *subject_uri, + b_uint64 subject_uri_len, + unsigned char *subject_bnode, + b_uint64 subject_bnode_len, unsigned char *property, + b_uint64 property_len, unsigned char *object_uri, + b_uint64 object_uri_len, unsigned char *object_bnode, + b_uint64 object_bnode_len, + unsigned char *object_literal, + b_uint64 object_literal_len, unsigned char *context, + b_uint64 context_len, unsigned char *datatype, + b_uint64 datatype_len, unsigned char *lang, + b_uint64 lang_len) +{ + b_triple_t *triple; + + B_LOG19 + ("b_triple_new_incomplete: %p %p %d %p %d %p %d %p %d %p %d %p %d %p %d %p %d %p %d", + ret, subject_uri, (int) subject_uri_len, subject_bnode, + (int) subject_bnode_len, property, (int) property_len, object_uri, + (int) object_uri_len, object_bnode, (int) object_bnode_len, + object_literal, (int) object_literal_len, context, (int) context_len, + datatype, (int) datatype_len, lang, (int) lang_len); + + if (!ret) + return B_ERROR_DATA; + + if (!(triple = (b_triple_t *) calloc (1, sizeof (b_triple_t)))) + return B_ERROR_MEMORY; + +#define B_TRIPLE_NEW( x, len ) \ + if(x) \ + { \ + triple->len = len > 0 ? len : strlen ((char *)x); \ + if (!(triple->x = b_string_alloc (x, triple->len))) \ + { \ + b_triple_destroy (triple); \ + return B_ERROR_MEMORY; \ + } \ + } + + B_TRIPLE_NEW (subject_uri, subject_uri_len); + B_TRIPLE_NEW (subject_bnode, subject_bnode_len); + B_TRIPLE_NEW (property, property_len); + B_TRIPLE_NEW (object_uri, object_uri_len); + B_TRIPLE_NEW (object_bnode, object_bnode_len); + B_TRIPLE_NEW (object_literal, object_literal_len); + B_TRIPLE_NEW (context, context_len); + B_TRIPLE_NEW (datatype, datatype_len); + B_TRIPLE_NEW (lang, lang_len); + + *ret = triple; + return B_OK; +} + +/** + * b_triple_new: + * @triple: The return pointer for the new b_triple_t data struct. + * @subject_uri: The subject URI. It can be NULL if the subject_object is not + * NULL. + * @subject_uri_len: The length of the subject_uri. Can be 0. + * @subject_bnode: The subject BNODE. + * @subject_bnode_len: The length of the subject_bnode. Can be 0. + * @property: The property of this triple. + * @property_len: The length of the property. Can be 0. + * @object_uri: The object as URI. It can be NULL if the triple has not a URI + * object. + * @object_uri_len: The length of the URI object. Can be 0. + * @object_bnode: The object as BNODE. It can be NULL if the triple has not a + * BNODE object. + * @object_bnode_len: The length of the BNODE object. Can be 0. + * @object_literal: The object as Literal. It can be NULL if the triple has not + * a Literal object. + * @object_literal_len: The length of the Literal Object. Can be 0. + * @context: The context. Can be NULL. + * @context_len: The Context Length. + * @datatype: The datatype for this Object Literal. It can be NULL. + * @datatype_len: The length of the datatype. + * @lang: The lang of this Object Literal. + * @lang_len: The length of the lang. + * @returns: The error code. + * + * Creates a new triples. This triple must be destroy with b_triple_destroy(). + **/ +b_error_t +b_triple_new (b_triple_t ** ret, unsigned char *subject_uri, + b_uint64 subject_uri_len, unsigned char *subject_bnode, + b_uint64 subject_bnode_len, unsigned char *property, + b_uint64 property_len, unsigned char *object_uri, + b_uint64 object_uri_len, unsigned char *object_bnode, + b_uint64 object_bnode_len, unsigned char *object_literal, + b_uint64 object_literal_len, unsigned char *context, + b_uint64 context_len, unsigned char *datatype, + b_uint64 datatype_len, unsigned char *lang, b_uint64 lang_len) +{ + b_error_t error; + + B_LOG19 + ("b_triple_new: %p %p %d %p %d %p %d %p %d %p %d %p %d %p %d %p %d %p %d", + ret, subject_uri, (int) subject_uri_len, subject_bnode, + (int) subject_bnode_len, property, (int) property_len, object_uri, + (int) object_uri_len, object_bnode, (int) object_bnode_len, + object_literal, (int) object_literal_len, context, (int) context_len, + datatype, (int) datatype_len, lang, (int) lang_len); + + if ((error = + b_triple_new_incomplete (ret, subject_uri, subject_uri_len, + subject_bnode, subject_bnode_len, property, + property_len, object_uri, object_uri_len, + object_bnode, object_bnode_len, + object_literal, object_literal_len, context, + context_len, datatype, datatype_len, lang, + lang_len)) != B_OK) + return error; + + if (b_triple_check (*ret) != B_OK) + { + b_triple_destroy (*ret); + return B_ERROR_DATA; + } + + return B_OK; +} + +b_error_t +b_triple_new_cache (b_tcache_t * cache, b_triple_t ** ret) +{ + b_triple_t *triple; + + B_LOG2 ("b_triple_new_cache: %p %p", cache, ret); + + if (!ret || !cache) + return B_ERROR_DATA; + + if (!(triple = (b_triple_t *) calloc (1, sizeof (b_triple_t)))) + return B_ERROR_MEMORY; + +#define B_TRIPLE_NEW_CACHE( x , l ) \ + if (cache->x) \ + { \ + triple->x = (unsigned char *)strdup ((char *)cache->x->what); \ + triple->l = cache->x->len; \ + } + + B_TRIPLE_NEW_CACHE (subject_uri, subject_uri_len); + B_TRIPLE_NEW_CACHE (subject_bnode, subject_bnode_len); + B_TRIPLE_NEW_CACHE (property, property_len); + B_TRIPLE_NEW_CACHE (object_uri, object_uri_len); + B_TRIPLE_NEW_CACHE (object_bnode, object_bnode_len); + B_TRIPLE_NEW_CACHE (object_literal, object_literal_len); + B_TRIPLE_NEW_CACHE (context, context_len); + B_TRIPLE_NEW_CACHE (datatype, datatype_len); + B_TRIPLE_NEW_CACHE (lang, lang_len); + + *ret = triple; + return B_OK; +} + +/** + * b_triple_destroy: + * @triple: The Pointer to the b_triple_t data struct. + * @returns: The error code. + * + * Destroies the triple data struct. + **/ +b_error_t +b_triple_destroy (b_triple_t * t) +{ + B_LOG1 ("b_triple_destroy: %p", t); + + if (!t) + return B_ERROR_DATA; + + if (t->subject_uri) + free (t->subject_uri); + + if (t->subject_bnode) + free (t->subject_bnode); + + if (t->property) + free (t->property); + + if (t->object_uri) + free (t->object_uri); + + if (t->object_bnode) + free (t->object_bnode); + + if (t->object_literal) + free (t->object_literal); + + if (t->context) + free (t->context); + + if (t->datatype) + free (t->datatype); + + if (t->lang) + free (t->lang); + + free (t); + + return B_OK; +} + +/** + * b_triple_print: + * @file: The FILE. + * @triple: The b_triple_t pointer. + * @returns: The error code. + * + * Prints the b_triple_t in n3 syntax in a FILE *. + **/ +b_error_t +b_triple_print (FILE * file, b_triple_t * triple) +{ + B_LOG2 ("b_triple_print: %p %p", file, triple); + + if (!file || !triple) + return B_ERROR_DATA; + + if (b_triple_check (triple) != B_OK) + return B_ERROR_DATA; + + if (triple->subject_uri) + fprintf (file, "<%s>", triple->subject_uri); + else + fprintf (file, "[%s]", triple->subject_bnode); + + fprintf (file, " <%s>", triple->property); + + if (triple->object_uri) + fprintf (file, " <%s>", triple->object_uri); + + if (triple->object_bnode) + fprintf (file, " [%s]", triple->object_bnode); + + if (triple->object_literal) + fprintf (file, " \"%s\"", triple->object_literal); + + if (triple->lang) + fprintf (file, "@%s", triple->lang); + + if (triple->datatype) + fprintf (file, "^^<%s>", triple->datatype); + + if (triple->context) + fprintf (file, " <%s>", triple->context); + + fprintf (file, "\n"); + + return B_OK; +} + +b_error_t +b_copy_triple (b_triple_t * src, b_triple_t ** dst) +{ + b_triple_t *new; + + B_LOG2 ("b_triple)copy: %p %p", src, dst); + + if (!src) + return B_ERROR_DATA; + + if (!(new = (b_triple_t *) calloc (1, sizeof (b_triple_t)))) + return B_ERROR_MEMORY; + +#define B_COPY_TRIPLE( x , len ) \ + if (src->x) \ + { \ + new->len = src->len > 0 ? src->len : strlen ((char *) src->x); \ + if (!(new->x = b_string_alloc (src->x, new->len))) \ + { \ + b_triple_destroy (new); \ + return B_ERROR_MEMORY; \ + } \ + } + + B_COPY_TRIPLE (subject_uri, subject_uri_len); + B_COPY_TRIPLE (subject_bnode, subject_bnode_len); + B_COPY_TRIPLE (property, property_len); + B_COPY_TRIPLE (object_uri, object_uri_len); + B_COPY_TRIPLE (object_bnode, object_bnode_len); + B_COPY_TRIPLE (object_literal, object_literal_len); + B_COPY_TRIPLE (context, context_len); + B_COPY_TRIPLE (datatype, datatype_len); + B_COPY_TRIPLE (lang, lang_len); + + *dst = new; + return B_OK; +} + +/* EOF */ Added: incubator/triplesoup/donations/TRIPLES-2-libb/tests/Makefile.in URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/tests/Makefile.in?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/tests/Makefile.in (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/tests/Makefile.in Wed Feb 21 13:56:43 2007 @@ -0,0 +1,32 @@ +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = b + +SIMPLE_PROGRAMS = \ + test1$(BIN_SUFFIX) \ + test2$(BIN_SUFFIX) \ + test3$(BIN_SUFFIX) \ + test4$(BIN_SUFFIX) \ + test5$(BIN_SUFFIX) \ + test6$(BIN_SUFFIX) \ + test7$(BIN_SUFFIX) \ + $(NULL) + + +include $(topsrcdir)/config/rules.mk + +LOCAL_INCLUDES += \ + -I$(srcdir)/../src \ + $(NULL) + +LOCAL_LIBS = \ + ../src/$(LIB_PREFIX)mozb_s.$(LIB_SUFFIX) + +LIBS += $(LOCAL_LIBS) + +$(SIMPLE_PROGRAMS): %$(BIN_SUFFIX): %.$(OBJ_SUFFIX) $(LOCAL_LIBS) Added: incubator/triplesoup/donations/TRIPLES-2-libb/tests/test1.c URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/tests/test1.c?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/tests/test1.c (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/tests/test1.c Wed Feb 21 13:56:43 2007 @@ -0,0 +1,39 @@ +#include + +#ifdef WIN32 +#define TEST1_FILE ".\\TEST1" +#else +#define TEST1_FILE "/tmp/test1" +#endif + +int +main (void) +{ + b_t *b; + b_uint64 value; + b_error_t err; + + fprintf (stderr, "Creating new b struct... "); + if ((err = b_new (&b, (unsigned char *) TEST1_FILE)) != B_OK) + { + fprintf (stderr, "b_new: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\nSetting the cache max to 16... "); + b_set_max_cache (b, 16); + + fprintf (stderr, "done.\nGetting the cache max... "); + b_get_max_cache (b, &value); + + fprintf (stderr, "%d.\nDestroing the b struct... ", (int) value); + + if ((err = b_destroy (b)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + return 0; +} Added: incubator/triplesoup/donations/TRIPLES-2-libb/tests/test2.c URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/tests/test2.c?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/tests/test2.c (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/tests/test2.c Wed Feb 21 13:56:43 2007 @@ -0,0 +1,63 @@ +#include + +#define TEST2_MAX 1024 + +#ifdef WIN32 +#define snprintf sprintf_s +#define TEST2_FILE ".\\TEST2" +#else +#define TEST2_FILE "/tmp/test2" +#endif + + +int +main (int argc, char **argv) +{ + b_t *b; + int i, c, m; + b_error_t err; + + fprintf (stderr, "Creating new b struct... "); + if ((err = b_new (&b, (unsigned char *) TEST2_FILE)) != B_OK) + { + fprintf (stderr, "b_new: %s\n", b_strerror (err)); + return 1; + } + + if (argc > 1 && (c = atoi (argv[1]))) + { + fprintf (stderr, "done.\nSetting cache to %d... ", c); + b_set_max_cache (b, c); + } + + if (argc <= 2 || !(m = atoi (argv[2]))) + m = TEST2_MAX; + + fprintf (stderr, "done.\nStoring %d datas...", m); + + for (i = 0; i < m; i++) + { + char s[128]; + + snprintf (s, sizeof (s), "test %d", i); + + if ((err = + b_add_type (b, B_TYPE_URI, (unsigned char *) s, + i % 2 ? 0 : strlen (s))) != B_OK) + { + fprintf (stderr, "b_add: %s\n", b_strerror (err)); + return 1; + } + } + + fprintf (stderr, "done.\nDestroing the b struct... "); + + if ((err = b_destroy (b)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + return 0; +} Added: incubator/triplesoup/donations/TRIPLES-2-libb/tests/test3.c URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/tests/test3.c?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/tests/test3.c (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/tests/test3.c Wed Feb 21 13:56:43 2007 @@ -0,0 +1,94 @@ +#include + +#define TEST3_MAX 4096 + +#ifdef WIN32 +#define snprintf sprintf_s +#define TEST3_FILE ".\\TEST3" +#else +#define TEST3_FILE "/tmp/test3" +#endif + +int +main (int argc, char **argv) +{ + b_t *b; + char s[128]; + int i, c, m; + b_error_t err; + + b_iterator_type_t *iterator; + unsigned char *what; + b_uint64 size; + + fprintf (stderr, "Creating new b struct... "); + if ((err = b_new (&b, (unsigned char *) TEST3_FILE)) != B_OK) + { + fprintf (stderr, "b_new: %s\n", b_strerror (err)); + return 1; + } + + if (argc > 1 && (c = atoi (argv[1]))) + { + fprintf (stderr, "done.\nSetting cache to %d... ", c); + b_set_max_cache (b, c); + } + + if (argc <= 2 || !(m = atoi (argv[2]))) + m = TEST3_MAX; + + fprintf (stderr, "done.\nStoring %d datas...", m); + + for (i = 0; i < m; i++) + { + snprintf (s, sizeof (s), "test %d", i); + + if ((err = + b_add_type (b, B_TYPE_URI, (unsigned char *) s, + i % 2 ? 0 : strlen (s))) != B_OK) + { + fprintf (stderr, "b_add: %s\n", b_strerror (err)); + return 1; + } + } + + fprintf (stderr, "done.\nCreating a iterator type... "); + if ((err = b_iterator_type_new (b, B_TYPE_URI, &iterator)) != B_OK) + { + fprintf (stderr, "b_iterator_new: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + + while ((err = b_iterator_type_step (iterator, &what, &size)) == B_OK + && what) + { + fprintf (stderr, "Next Data: %s (%d)\n", what, (int) size); + free (what); + } + + if (err != B_OK) + { + fprintf (stderr, "b_iterator_step: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\nDestroying the iterator type... "); + if ((err = b_iterator_type_destroy (iterator)) != B_OK) + { + fprintf (stderr, "b_iterator_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\nDestroing the b struct... "); + + if ((err = b_destroy (b)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + return 0; +} Added: incubator/triplesoup/donations/TRIPLES-2-libb/tests/test4.c URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/tests/test4.c?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/tests/test4.c (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/tests/test4.c Wed Feb 21 13:56:43 2007 @@ -0,0 +1,139 @@ +#include + +#define TEST4_MAX 4096 + +#ifdef WIN32 +#define snprintf sprintf_s +#define TEST4_FILE ".\\TEST4" +#else +#define TEST4_FILE "/tmp/test4" +#endif + +int +main (int argc, char **argv) +{ + b_t *b; + b_triple_t *triple; + char subject[128]; + int subject_type; + char property[128]; + char object[128]; + int object_type; + char context[128]; + int context_type; + char datatype[128]; + int datatype_type; + char lang[128]; + int lang_type; + int i, m, c; + b_error_t err; + + b_iterator_triple_t *iterator; + + fprintf (stderr, "Creating new b struct... "); + if ((err = b_new (&b, (unsigned char *) TEST4_FILE)) != B_OK) + { + fprintf (stderr, "b_new: %s\n", b_strerror (err)); + return 1; + } + + if (argc > 1 && (c = atoi (argv[1]))) + { + fprintf (stderr, "done.\nSetting cache to %d... ", c); + b_set_max_cache (b, c); + } + + if (argc <= 2 || !(m = atoi (argv[2]))) + m = TEST4_MAX; + + fprintf (stderr, "done.\nStoring %d triples...", m); + + for (i = 0; i < m; i++) + { + subject_type = i % 2; + snprintf (subject, sizeof (subject), "subject %d %s", i % 111, + !subject_type ? "uri" : "bnode"); + + snprintf (property, sizeof (property), "property %d", i); + + object_type = i % 3; + snprintf (object, sizeof (object), "object %d %s", i % 333, + !object_type ? "uri" : object_type == + 1 ? "bnode" : "literal"); + + context_type = i % 4; + snprintf (context, sizeof (context), "context %d", i % 222); + + datatype_type = i % 5; + snprintf (datatype, sizeof (datatype), "datatype %d", i % 222); + + lang_type = i % 6; + snprintf (lang, sizeof (lang), "lang %d", i % 222); + + if ((err = + b_triple_new (&triple, + !subject_type ? (unsigned char *) subject : NULL, 0, + !subject_type ? NULL : (unsigned char *) subject, 0, + (unsigned char *) property, 0, + !object_type ? (unsigned char *) object : NULL, 0, + object_type == 1 ? (unsigned char *) object : NULL, + 0, + object_type == 2 ? (unsigned char *) object : NULL, + 0, context_type ? (unsigned char *) context : NULL, + 0, datatype_type ? (unsigned char *) datatype : NULL, + 0, lang_type ? (unsigned char *) lang : NULL, + 0)) != B_OK) + { + fprintf (stderr, "b_triple_new: %s\n", b_strerror (err)); + return 1; + } + + if ((err = b_add_triple (b, triple)) != B_OK) + { + fprintf (stderr, "b_add: %s\n", b_strerror (err)); + return 1; + } + + b_triple_destroy (triple); + } + + fprintf (stderr, "done.\nCreating iterator... "); + if ((err = b_iterator_triple_new (b, &iterator, NULL)) != B_OK) + { + fprintf (stderr, "b_iterator_new: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + + while ((err = b_iterator_triple_step (iterator, &triple)) == B_OK && triple) + { + fprintf (stderr, "Next data: "); + b_triple_print (stderr, triple); + b_triple_destroy (triple); + } + + if (err != B_OK) + { + fprintf (stderr, "b_iterator_step: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "Destroying iterator... "); + if ((err = b_iterator_triple_destroy (iterator)) != B_OK) + { + fprintf (stderr, "b_iterator_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\nDestroing the b struct... "); + + if ((err = b_destroy (b)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + return 0; +} Added: incubator/triplesoup/donations/TRIPLES-2-libb/tests/test5.c URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/tests/test5.c?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/tests/test5.c (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/tests/test5.c Wed Feb 21 13:56:43 2007 @@ -0,0 +1,158 @@ +#include + +#define TEST5_MAX 1024 + +#ifdef WIN32 +#define snprintf sprintf_s +#define TEST5_FILE ".\\TEST5" +#else +#define TEST5_FILE "/tmp/test5" +#endif + +int +main (int argc, char **argv) +{ + b_t *b; + b_triple_t *triple; + char subject[128]; + int subject_type; + char property[128]; + char object[128]; + int object_type; + char context[128]; + int context_type; + char datatype[128]; + int datatype_type; + char lang[128]; + int lang_type; + int i, m, c; + b_uint64 count; + b_error_t err; + + fprintf (stderr, "Creating new b struct... "); + if ((err = b_new (&b, (unsigned char *) TEST5_FILE)) != B_OK) + { + fprintf (stderr, "b_new: %s\n", b_strerror (err)); + return 1; + } + + if (argc > 1 && (c = atoi (argv[1]))) + { + fprintf (stderr, "done.\nSetting cache to %d... ", c); + b_set_max_cache (b, c); + } + + if (argc <= 2 || !(m = atoi (argv[2]))) + m = TEST5_MAX; + + fprintf (stderr, "done.\nStoring %d triples...", m); + + for (i = 0; i < m; i++) + { + subject_type = i % 2; + snprintf (subject, sizeof (subject), "subject %d %s", i % 111, + !subject_type ? "uri" : "bnode"); + + snprintf (property, sizeof (property), "property %d", i % 222); + + object_type = i % 3; + snprintf (object, sizeof (object), "object %d %s", i % 333, + !object_type ? "uri" : object_type == + 1 ? "bnode" : "literal"); + + context_type = i % 4; + snprintf (context, sizeof (context), "context %d", i % 222); + + datatype_type = i % 6; + snprintf (datatype, sizeof (datatype), "datatype %d", i % 222); + + lang_type = i % 6; + snprintf (lang, sizeof (lang), "lang %d", i % 222); + + if ((err = + b_triple_new (&triple, + !subject_type ? (unsigned char *) subject : NULL, 0, + !subject_type ? NULL : (unsigned char *) subject, 0, + (unsigned char *) property, 0, + !object_type ? (unsigned char *) object : NULL, 0, + object_type == 1 ? (unsigned char *) object : NULL, + 0, + object_type == 2 ? (unsigned char *) object : NULL, + 0, context_type ? (unsigned char *) context : NULL, + 0, datatype_type ? (unsigned char *) datatype : NULL, + 0, lang_type ? (unsigned char *) lang : NULL, + 0)) != B_OK) + { + fprintf (stderr, "b_triple_new: %s\n", b_strerror (err)); + return 1; + } + + if ((err = b_add_triple (b, triple)) != B_OK) + { + fprintf (stderr, "b_triple_new: %s\n", b_strerror (err)); + return 1; + } + + b_triple_destroy (triple); + } + + fprintf (stderr, "done.\nNumber of uris: "); + if ((err = b_count_type (b, B_TYPE_URI, &count)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "%d\nNumber of properties: ", (int) count); + if ((err = b_count_type (b, B_TYPE_PROPERTY, &count)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "%d\nNumber of literals: ", (int) count); + if ((err = b_count_type (b, B_TYPE_LITERAL, &count)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "%d\nNumber of bnodes: ", (int) count); + if ((err = b_count_type (b, B_TYPE_BNODE, &count)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "%d\nNumber of contexts: ", (int) count); + if ((err = b_count_type (b, B_TYPE_CONTEXT, &count)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "%d\nNumber of datatypes: ", (int) count); + if ((err = b_count_type (b, B_TYPE_DATATYPE, &count)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "%d\nNumber of triples: ", (int) count); + if ((err = b_count_triple (b, &count)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "%d\nDestroing the b struct... ", (int) count); + + if ((err = b_destroy (b)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + return 0; +} Added: incubator/triplesoup/donations/TRIPLES-2-libb/tests/test6.c URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/tests/test6.c?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/tests/test6.c (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/tests/test6.c Wed Feb 21 13:56:43 2007 @@ -0,0 +1,159 @@ +#include + +#define TEST6_MAX 1024 + +#ifdef WIN32 +#define snprintf sprintf_s +#define TEST6_FILE ".\\TEST6" +#else +#define TEST6_FILE "/tmp/test6" +#endif + +int +main (int argc, char **argv) +{ + b_t *b; + b_triple_t *triple; + b_triple_t *compare; + char subject[128]; + int subject_type; + char property[128]; + char object[128]; + int object_type; + char context[128]; + int context_type; + char datatype[128]; + int datatype_type; + char lang[128]; + int lang_type; + int i, m, c; + b_error_t err; + + b_iterator_triple_t *iterator; + + fprintf (stderr, "Creating new b struct... "); + if ((err = b_new (&b, (unsigned char *) TEST6_FILE)) != B_OK) + { + fprintf (stderr, "b_new: %s\n", b_strerror (err)); + return 1; + } + + if (argc > 1 && (c = atoi (argv[1]))) + { + fprintf (stderr, "done.\nSetting cache to %d... ", c); + b_set_max_cache (b, c); + } + + if (argc <= 2 || !(m = atoi (argv[2]))) + m = TEST6_MAX; + + fprintf (stderr, "done.\nStoring %d triples...", m); + + for (i = 0; i < m; i++) + { + subject_type = i % 2; + snprintf (subject, sizeof (subject), "subject %d %s", i % 111, + !subject_type ? "uri" : "bnode"); + + snprintf (property, sizeof (property), "property %d", i); + + object_type = i % 3; + snprintf (object, sizeof (object), "object %d %s", i % 333, + !object_type ? "uri" : object_type == + 1 ? "bnode" : "literal"); + + context_type = i % 4; + snprintf (context, sizeof (context), "context %d", i % 222); + + datatype_type = 1; + snprintf (datatype, sizeof (datatype), "datatype"); + + lang_type = i % 7; + snprintf (lang, sizeof (lang), "lang %d", i % 222); + + if ((err = + b_triple_new (&triple, + !subject_type ? (unsigned char *) subject : NULL, 0, + !subject_type ? NULL : (unsigned char *) subject, 0, + (unsigned char *) property, 0, + !object_type ? (unsigned char *) object : NULL, 0, + object_type == 1 ? (unsigned char *) object : NULL, + 0, + object_type == 2 ? (unsigned char *) object : NULL, + 0, context_type ? (unsigned char *) context : NULL, + 0, datatype_type ? (unsigned char *) datatype : NULL, + 0, lang_type ? (unsigned char *) lang : NULL, + 0)) != B_OK) + { + fprintf (stderr, "b_triple_new: %s\n", b_strerror (err)); + return 1; + } + + if ((err = b_add_triple (b, triple)) != B_OK) + { + fprintf (stderr, "b_triple_new: %s\n", b_strerror (err)); + return 1; + } + + b_triple_destroy (triple); + } + + fprintf (stderr, "done.\nCreating a incomplete triple..."); + + if ((err = + b_triple_new_incomplete (&compare, NULL, 0, NULL, 0, NULL, 0, NULL, 0, + NULL, 0, NULL, 0, NULL, 0, + (unsigned char *) "datatype", 0, NULL, + 0)) != B_OK) + { + fprintf (stderr, "b_triple_new_incomplete: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\nCreating iterator... "); + if ((err = b_iterator_triple_new (b, &iterator, compare)) != B_OK) + { + fprintf (stderr, "b_iterator_new: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\nDestroing the incomplete triple..."); + if ((err = b_triple_destroy (compare)) != B_OK) + { + fprintf (stderr, "b_triple_desotry: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + + while ((err = b_iterator_triple_step (iterator, &triple)) == B_OK && triple) + { + fprintf (stderr, "Next data: "); + b_triple_print (stderr, triple); + b_triple_destroy (triple); + } + + if (err != B_OK) + { + fprintf (stderr, "b_iterator_step: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "Destroying iterator... "); + if ((err = b_iterator_triple_destroy (iterator)) != B_OK) + { + fprintf (stderr, "b_iterator_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\nDestroing the b struct... "); + + if ((err = b_destroy (b)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + return 0; +} Added: incubator/triplesoup/donations/TRIPLES-2-libb/tests/test7.c URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/tests/test7.c?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/tests/test7.c (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/tests/test7.c Wed Feb 21 13:56:43 2007 @@ -0,0 +1,194 @@ +#include + +#define TEST7_MAX 1024 + +#ifdef WIN32 +#define snprintf sprintf_s +#define TEST7_FILE ".\\TEST7" +#else +#define TEST7_FILE "/tmp/test7" +#endif + +int +main (int argc, char **argv) +{ + b_t *b; + b_triple_t *triple; + char subject[128]; + int subject_type; + char property[128]; + char object[128]; + int object_type; + char context[128]; + int context_type; + char datatype[128]; + char lang[128]; + int lang_type; + int i, m, c; + b_error_t err; + + b_iterator_triple_t *iterator; + + fprintf (stderr, "Creating new b struct... "); + if ((err = b_new (&b, (unsigned char *) TEST7_FILE)) != B_OK) + { + fprintf (stderr, "b_new: %s\n", b_strerror (err)); + return 1; + } + + if (argc > 1 && (c = atoi (argv[1]))) + { + fprintf (stderr, "done.\nSetting cache to %d... ", c); + b_set_max_cache (b, c); + } + + if (argc <= 2 || !(m = atoi (argv[2]))) + m = TEST7_MAX; + + fprintf (stderr, "done.\nStoring %d triples...", m); + + for (i = 0; i < m; i++) + { + subject_type = i % 2; + snprintf (subject, sizeof (subject), "subject %d %s", i % 111, + !subject_type ? "uri" : "bnode"); + + snprintf (property, sizeof (property), "property %d", i); + + object_type = i % 3; + snprintf (object, sizeof (object), "object %d %s", i % 333, + !object_type ? "uri" : object_type == + 1 ? "bnode" : "literal"); + + context_type = i % 4; + snprintf (context, sizeof (context), "context %d", i % 222); + + snprintf (datatype, sizeof (datatype), "datatype"); + + lang_type = i % 7; + snprintf (lang, sizeof (lang), "lang %d", i % 222); + + if ((err = + b_triple_new (&triple, + !subject_type ? (unsigned char *) subject : NULL, 0, + !subject_type ? NULL : (unsigned char *) subject, 0, + (unsigned char *) property, 0, + !object_type ? (unsigned char *) object : NULL, 0, + object_type == 1 ? (unsigned char *) object : NULL, + 0, + object_type == 2 ? (unsigned char *) object : NULL, + 0, context_type ? (unsigned char *) context : NULL, + 0, (unsigned char *) datatype, + 0, lang_type ? (unsigned char *) lang : NULL, + 0)) != B_OK) + { + fprintf (stderr, "b_triple_new: %s\n", b_strerror (err)); + return 1; + } + + if ((err = b_add_triple (b, triple)) != B_OK) + { + fprintf (stderr, "b_triple_new: %s\n", b_strerror (err)); + return 1; + } + + b_triple_destroy (triple); + } + + fprintf (stderr, "done.\nDeleting %d triples...", m / 2); + + for (i = 0; i < m; i++) + { + if ((i % 2)) + { + subject_type = i % 2; + snprintf (subject, sizeof (subject), "subject %d %s", i % 111, + !subject_type ? "uri" : "bnode"); + + snprintf (property, sizeof (property), "property %d", i); + + object_type = i % 3; + snprintf (object, sizeof (object), "object %d %s", i % 333, + !object_type ? "uri" : object_type == + 1 ? "bnode" : "literal"); + + context_type = i % 4; + snprintf (context, sizeof (context), "context %d", i % 222); + + snprintf (datatype, sizeof (datatype), "datatype"); + + lang_type = i % 7; + snprintf (lang, sizeof (lang), "lang %d", i % 222); + + if ((err = + b_triple_new (&triple, + !subject_type ? (unsigned char *) subject : NULL, + 0, + !subject_type ? NULL : (unsigned char *) subject, + 0, (unsigned char *) property, 0, + !object_type ? (unsigned char *) object : NULL, + 0, + object_type == + 1 ? (unsigned char *) object : NULL, 0, + object_type == + 2 ? (unsigned char *) object : NULL, 0, + context_type ? (unsigned char *) context : NULL, + 0, + (unsigned char *) datatype, 0, + lang_type ? (unsigned char *) lang : NULL, + 0)) != B_OK) + { + fprintf (stderr, "b_triple_new: %s\n", b_strerror (err)); + return 1; + } + + if ((err = b_remove_triple (b, triple)) != B_OK) + { + fprintf (stderr, "b_triple_new: %s\n", b_strerror (err)); + return 1; + } + + b_triple_destroy (triple); + } + } + + fprintf (stderr, "done.\nCreating iterator... "); + if ((err = b_iterator_triple_new (b, &iterator, NULL)) != B_OK) + { + fprintf (stderr, "b_iterator_new: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + + while ((err = b_iterator_triple_step (iterator, &triple)) == B_OK && triple) + { + fprintf (stderr, "Next data: "); + b_triple_print (stderr, triple); + b_triple_destroy (triple); + } + + if (err != B_OK) + { + fprintf (stderr, "b_iterator_step: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "Destroying iterator... "); + if ((err = b_iterator_triple_destroy (iterator)) != B_OK) + { + fprintf (stderr, "b_iterator_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\nDestroing the b struct... "); + + if ((err = b_destroy (b)) != B_OK) + { + fprintf (stderr, "b_destroy: %s\n", b_strerror (err)); + return 1; + } + + fprintf (stderr, "done.\n"); + return 0; +} Added: incubator/triplesoup/donations/TRIPLES-2-libb/utils/Makefile.in URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/utils/Makefile.in?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/utils/Makefile.in (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/utils/Makefile.in Wed Feb 21 13:56:43 2007 @@ -0,0 +1,37 @@ +# (c) 2006 Satis Superque Merce B.V. All rights reserved. This code +# contains trade secrets of Satis Superque Merce B.V. and any +# unauthorized use or disclosure is strictly prohibited. +# +# $Id: Makefile.in 29834 2006-10-19 16:22:05Z Andrea Marchesini $ +# + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = bproc + +REQUIRES = b + +SIMPLE_PROGRAMS = \ + bproc$(BIN_SUFFIX) \ + $(NULL) + + +include $(topsrcdir)/config/rules.mk + +LOCAL_INCLUDES += \ + -I$(srcdir)/../src \ + -I$(srcdir) \ + $(NULL) + +LOCAL_LIBS = \ + ../src/$(LIB_PREFIX)mozb_s.$(LIB_SUFFIX) \ + $(NULL) + +LIBS += $(LOCAL_LIBS) + +$(SIMPLE_PROGRAMS): %$(BIN_SUFFIX): %.$(OBJ_SUFFIX) $(LOCAL_LIBS) Added: incubator/triplesoup/donations/TRIPLES-2-libb/utils/bproc.c URL: http://svn.apache.org/viewvc/incubator/triplesoup/donations/TRIPLES-2-libb/utils/bproc.c?view=auto&rev=510255 ============================================================================== --- incubator/triplesoup/donations/TRIPLES-2-libb/utils/bproc.c (added) +++ incubator/triplesoup/donations/TRIPLES-2-libb/utils/bproc.c Wed Feb 21 13:56:43 2007 @@ -0,0 +1,456 @@ +#include "b.h" + +static int usage (char *what, int ret); +static b_error_t serialise_type (b_t * data, b_type_t type); +static b_error_t serialise_triple (b_t * data); +static b_error_t add_type (b_t * data, b_type_t type, char *what); +static b_error_t remove_type (b_t * data, b_type_t type, char *what); +static b_error_t add_triple (b_t * data, char *su, char *sb, char *p, + char *ou, char *ob, char *ol, char *c, + char *d, char *l); +static b_error_t remove_triple (b_t * data, char *su, char *sb, char *p, + char *ou, char *ob, char *ol, char *c, + char *d, char *l); +static b_error_t count_type (b_t * data, b_type_t type); +static b_error_t count_triple (b_t * data); + +int +main (int argc, char **argv) +{ + b_error_t error; + b_t *data; + int i; + + if (argc < 2) + return usage (argv[0], 1); + + if ((error = b_new (&data, (unsigned char *) argv[1])) != B_OK) + { + fprintf (stderr, "Error (b_new): %s\n", b_strerror (error)); + return 1; + } + + for (i = 2; i < argc; i++) + { + if (!strcmp (argv[i], "-h") || !strcmp (argv[i], "--help")) + { + b_destroy (data); + return usage (argv[0], 0); + } + + else if (!strcmp (argv[i], "-us") + || !strcmp (argv[i], "--uri_serialise")) + { + error = serialise_type (data, B_TYPE_URI); + break; + } + + else if (!strcmp (argv[i], "-bs") + || !strcmp (argv[i], "--bnode_serialise")) + { + error = serialise_type (data, B_TYPE_BNODE); + break; + } + + else if (!strcmp (argv[i], "-ls") + || !strcmp (argv[i], "--literal_serialise")) + { + error = serialise_type (data, B_TYPE_LITERAL); + break; + } + + else if (!strcmp (argv[i], "-ps") + || !strcmp (argv[i], "--property_serialise")) + { + error = serialise_type (data, B_TYPE_PROPERTY); + break; + } + + else if (!strcmp (argv[i], "-ds") + || !strcmp (argv[i], "--datatype_serialise")) + { + error = serialise_type (data, B_TYPE_DATATYPE); + break; + } + + else if (!strcmp (argv[i], "-cs") + || !strcmp (argv[i], "--context_serialise")) + { + error = serialise_type (data, B_TYPE_CONTEXT); + break; + } + + else if (!strcmp (argv[i], "-s") || !strcmp (argv[i], "--serialise")) + { + error = serialise_triple (data); + break; + } + + else if (!strcmp (argv[i], "-uc") || !strcmp (argv[i], "--uri_count")) + { + error = count_type (data, B_TYPE_URI); + break; + } + + else if (!strcmp (argv[i], "-bc") || !strcmp (argv[i], "--bnode_count")) + { + error = count_type (data, B_TYPE_BNODE); + break; + } + + else if (!strcmp (argv[i], "-lc") + || !strcmp (argv[i], "--literal_count")) + { + error = count_type (data, B_TYPE_LITERAL); + break; + } + + else if (!strcmp (argv[i], "-pc") + || !strcmp (argv[i], "--property_count")) + { + error = count_type (data, B_TYPE_PROPERTY); + break; + } + + else if (!strcmp (argv[i], "-dc") + || !strcmp (argv[i], "--datatype_count")) + { + error = count_type (data, B_TYPE_DATATYPE); + break; + } + + else if (!strcmp (argv[i], "-cc") + || !strcmp (argv[i], "--context_count")) + { + error = count_type (data, B_TYPE_CONTEXT); + break; + } + + else if (!strcmp (argv[i], "-c") || !strcmp (argv[i], "--count")) + { + error = count_triple (data); + break; + } + + else if ((!strcmp (argv[i], "-ua") || !strcmp (argv[i], "--uri_add")) + && argv[++i]) + { + error = add_type (data, B_TYPE_URI, argv[i]); + break; + } + + else if ((!strcmp (argv[i], "-ba") || !strcmp (argv[i], "--bnode_add")) + && argv[++i]) + { + error = add_type (data, B_TYPE_BNODE, argv[i]); + break; + } + + else + if ((!strcmp (argv[i], "-la") || !strcmp (argv[i], "--literal_add")) + && argv[++i]) + { + error = add_type (data, B_TYPE_LITERAL, argv[i]); + break; + } + + else + if ((!strcmp (argv[i], "-pa") || !strcmp (argv[i], "--property_add")) + && argv[++i]) + { + error = add_type (data, B_TYPE_PROPERTY, argv[i]); + break; + } + + else + if ((!strcmp (argv[i], "-da") || !strcmp (argv[i], "--datatype_add")) + && argv[++i]) + { + error = add_type (data, B_TYPE_DATATYPE, argv[i]); + } + + else if ((!strcmp (argv[i], "-a") || !strcmp (argv[i], "--add")) + && (i + 9) < argc) + { + error = + add_triple (data, argv[i + 1], argv[i + 2], argv[i + 3], + argv[i + 4], argv[i + 5], argv[i + 6], argv[i + 7], + argv[i + 8], argv[i + 9]); + break; + } + + else if ((!strcmp (argv[i], "-ur") || !strcmp (argv[i], "--uri_remove")) + && argv[++i]) + { + error = remove_type (data, B_TYPE_URI, argv[i]); + break; + } + + else + if ((!strcmp (argv[i], "-br") || !strcmp (argv[i], "--bnode_remove")) + && argv[++i]) + { + error = remove_type (data, B_TYPE_BNODE, argv[i]); + break; + } + + else + if ((!strcmp (argv[i], "-lr") + || !strcmp (argv[i], "--literal_remove")) && argv[++i]) + { + error = remove_type (data, B_TYPE_LITERAL, argv[i]); + break; + } + + else + if ((!strcmp (argv[i], "-pr") + || !strcmp (argv[i], "--property_remove")) && argv[++i]) + { + error = remove_type (data, B_TYPE_PROPERTY, argv[i]); + break; + } + + else + if ((!strcmp (argv[i], "-dr") + || !strcmp (argv[i], "--datatype_remove")) && argv[++i]) + { + error = remove_type (data, B_TYPE_DATATYPE, argv[i]); + } + + else if ((!strcmp (argv[i], "-r") || !strcmp (argv[i], "--remove")) + && (i + 9) < argc) + { + error = + remove_triple (data, argv[i + 1], argv[i + 2], argv[i + 3], + argv[i + 4], argv[i + 5], argv[i + 6], argv[i + 7], + argv[i + 8], argv[i + 9]); + break; + } + + else + { + fprintf (stderr, "Unkown option: %s\n", argv[i]); + b_destroy (data); + return 1; + } + } + + if (error) + { + fprintf (stderr, "Error: %s\n", b_strerror (error)); + return 1; + } + + if ((error = b_destroy (data))) + { + fprintf (stderr, "Error (b_destroy): %s\n", b_strerror (error)); + return 1; + } + + return 0; +} + +static int +usage (char *what, int ret) +{ + fprintf (stderr, "%s path [options]\n\n", what); + fprintf (stderr, "Options are:\n"); + fprintf (stderr, + "-us or --uri_serialise | Serialise all uris\n"); + fprintf (stderr, + "-bs or --bnode_serialise | Serialise all bnodes\n"); + fprintf (stderr, + "-ls or --literal_serialise | Serialise all literals\n"); + fprintf (stderr, + "-ps or --property_serialise | Serialise all properties\n"); + fprintf (stderr, + "-cs or --context_serialise | Serialise all contexts\n"); + fprintf (stderr, + "-ds or --datatype_serialise | Serialise all datatypes\n"); + fprintf (stderr, + "-s or --serialise | Serialise all triples\n"); + fprintf (stderr, + "-uc or --uri_count | Count all uris\n"); + fprintf (stderr, + "-bc or --bnode_count | Count all bnodes\n"); + fprintf (stderr, + "-lc or --literal_count | Count all literals\n"); + fprintf (stderr, + "-pc or --property_count | Count all properties\n"); + fprintf (stderr, + "-cc or --context_count | Count all contexts\n"); + fprintf (stderr, + "-dc or --datatype_count | Count all datatypes\n"); + fprintf (stderr, + "-c or --count | Count all triples\n"); + fprintf (stderr, + "-ua or --uri_add | Add a uri\n"); + fprintf (stderr, + "-ba or --bnode_add | Add a bnode\n"); + fprintf (stderr, + "-la or --literal_add | Add a literal\n"); + fprintf (stderr, + "-pa or --property_add | Add a property\n"); + fprintf (stderr, + "-ca or --context_add | Add a context\n"); + fprintf (stderr, + "-da or --datatype_add | Add a datatype\n"); + fprintf (stderr, + "-a or --add

    | Add a triple\n"); + fprintf (stderr, + "-ur or --uri_remove | Remove a uri\n"); + fprintf (stderr, + "-br or --bnode_remove | Remove a bnode\n"); + fprintf (stderr, + "-lr or --literal_remove | Remove a literal\n"); + fprintf (stderr, + "-pr or --property_remove | Remove a property\n"); + fprintf (stderr, + "-cr or --context_remove | Remove a context\n"); + fprintf (stderr, + "-dr or --datatype_remove | Remove a datatype\n"); + fprintf (stderr, + "-r or --remove

      | Remove a triple\n"); + fprintf (stderr, "\nFor the triples: if a item is empty, use '-'\n\n"); + + return ret; +} + +static b_error_t +serialise_type (b_t * data, b_type_t type) +{ + unsigned char *what; + b_error_t error; + b_iterator_type_t *iterator; + + if ((error = b_iterator_type_new (data, type, &iterator)) != B_OK) + return error; + + while ((error = b_iterator_type_step (iterator, &what, NULL)) == B_OK + && what) + { + fprintf (stdout, "%s\n", what); + free (what); + } + + if (error != B_OK) + return error; + + error = b_iterator_type_destroy (iterator); + return error; +} + +static b_error_t +serialise_triple (b_t * data) +{ + b_triple_t *what; + b_error_t error; + b_iterator_triple_t *iterator; + + if ((error = b_iterator_triple_new (data, &iterator, NULL)) != B_OK) + return error; + + while ((error = b_iterator_triple_step (iterator, &what)) == B_OK && what) + { + b_triple_print (stdout, what); + b_triple_destroy (what); + } + + if (error != B_OK) + return error; + + error = b_iterator_triple_destroy (iterator); + return error; +} + +static b_error_t +count_type (b_t * data, b_type_t type) +{ + b_error_t error; + b_uint64 n; + + if ((error = b_count_type (data, type, &n))) + return error; + + fprintf (stdout, "%d\n", (int) n); + return B_OK; +} + +static b_error_t +count_triple (b_t * data) +{ + b_error_t error; + b_uint64 n; + + if ((error = b_count_triple (data, &n))) + return error; + + fprintf (stdout, "%d\n", (int) n); + return B_OK; +} + +static b_error_t +add_type (b_t * data, b_type_t type, char *what) +{ + return b_add_type (data, type, (unsigned char *) what, 0); +} + +static b_error_t +add_triple (b_t * data, char *su, char *sb, char *p, char *ou, + char *ob, char *ol, char *c, char *d, char *l) +{ + b_triple_t *triple; + b_error_t error; + + if ((error = + b_triple_new (&triple, + (unsigned char *) (strcmp (su, "-") ? su : NULL), 0, + (unsigned char *) (strcmp (sb, "-") ? sb : NULL), 0, + (unsigned char *) (strcmp (p, "-") ? p : NULL), 0, + (unsigned char *) (strcmp (ou, "-") ? ou : NULL), 0, + (unsigned char *) (strcmp (ob, "-") ? ob : NULL), 0, + (unsigned char *) (strcmp (ol, "-") ? ol : NULL), 0, + (unsigned char *) (strcmp (c, "-") ? c : NULL), 0, + (unsigned char *) (strcmp (d, "-") ? d : NULL), 0, + (unsigned char *) (strcmp (l, "-") ? l : NULL), 0))) + return error; + + error = b_add_triple (data, triple); + + b_triple_destroy (triple); + return error; +} + +static b_error_t +remove_type (b_t * data, b_type_t type, char *what) +{ + return b_remove_type (data, type, (unsigned char *) what, 0); +} + +static b_error_t +remove_triple (b_t * data, char *su, char *sb, char *p, char *ou, + char *ob, char *ol, char *c, char *d, char *l) +{ + b_triple_t *triple; + b_error_t error; + + if ((error = + b_triple_new (&triple, + (unsigned char *) (strcmp (su, "-") ? su : NULL), 0, + (unsigned char *) (strcmp (sb, "-") ? sb : NULL), 0, + (unsigned char *) (strcmp (p, "-") ? p : NULL), 0, + (unsigned char *) (strcmp (ou, "-") ? ou : NULL), 0, + (unsigned char *) (strcmp (ob, "-") ? ob : NULL), 0, + (unsigned char *) (strcmp (ol, "-") ? ol : NULL), 0, + (unsigned char *) (strcmp (c, "-") ? c : NULL), 0, + (unsigned char *) (strcmp (d, "-") ? d : NULL), 0, + (unsigned char *) (strcmp (l, "-") ? l : NULL), 0))) + return error; + + error = b_remove_triple (data, triple); + + b_triple_destroy (triple); + return error; +} + +/* EOF */