|
@@ -69,163 +69,6 @@ uint8_t *unescape_unicode (const uint8_t *esc_str, size_t size)
|
|
|
}
|
|
|
|
|
|
|
|
|
-LSUP_Term **
|
|
|
-LSUP_obj_list_add (LSUP_Term **ol, LSUP_Term *o)
|
|
|
-{
|
|
|
- size_t i = 0;
|
|
|
- while (ol[i++]); // Count includes sentinel.
|
|
|
- LSUP_Term **ret = realloc (ol, sizeof (*ol) * (i + 1));
|
|
|
- if (!ret) return NULL;
|
|
|
-
|
|
|
- ret[i - 1] = o;
|
|
|
- ret[i] = NULL;
|
|
|
-
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-LSUP_PredObjList *
|
|
|
-LSUP_pred_obj_list_new (void)
|
|
|
-{
|
|
|
- /*
|
|
|
- * Init state:
|
|
|
- * {p: [NULL], o: [NULL]}
|
|
|
- */
|
|
|
- LSUP_PredObjList *po;
|
|
|
- MALLOC_GUARD (po, NULL);
|
|
|
- // Set sentinels.
|
|
|
- CALLOC_GUARD (po->p, NULL);
|
|
|
- CALLOC_GUARD (po->o, NULL);
|
|
|
-
|
|
|
- return po;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-void
|
|
|
-LSUP_pred_obj_list_free (LSUP_PredObjList *po)
|
|
|
-{
|
|
|
- log_debug ("Freeing predicate object list.");
|
|
|
- for (size_t i = 0; po->p[i]; i++) {
|
|
|
- // Free individual predicate handles.
|
|
|
- LSUP_term_free (po->p[i]);
|
|
|
- }
|
|
|
- // Free pred list.
|
|
|
- free (po->p);
|
|
|
-
|
|
|
- for (size_t i = 0; po->o[i]; i++) {
|
|
|
- for (size_t j = 0; po->o[i][j]; j++) {
|
|
|
- // Free individual term handles.
|
|
|
- LSUP_term_free (po->o[i][j]);
|
|
|
- }
|
|
|
- // Free object list.
|
|
|
- free (po->o[i]);
|
|
|
- }
|
|
|
- // Free list of object lists.
|
|
|
- free (po->o);
|
|
|
-
|
|
|
- free (po);
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-LSUP_rc
|
|
|
-LSUP_pred_obj_list_add (LSUP_PredObjList *po, LSUP_Term *p, LSUP_Term **o)
|
|
|
-{
|
|
|
- size_t i;
|
|
|
-
|
|
|
- i = 0;
|
|
|
- while (po->p[i++]); // Count includes sentinel.
|
|
|
- LSUP_Term **tmp_p = realloc (po->p, sizeof (*po->p) * (i + 1));
|
|
|
- if (!tmp_p) return LSUP_MEM_ERR;
|
|
|
- tmp_p[i - 1] = p;
|
|
|
- tmp_p[i] = NULL;
|
|
|
- po->p = tmp_p;
|
|
|
-
|
|
|
- i = 0;
|
|
|
- while (po->o[i++]);
|
|
|
- LSUP_Term ***tmp_o = realloc (po->o, sizeof (*po->o) * (i + 1));
|
|
|
- if (!tmp_o) return LSUP_MEM_ERR;
|
|
|
- tmp_o[i - 1] = o;
|
|
|
- tmp_o[i] = NULL;
|
|
|
- po->o = tmp_o;
|
|
|
-
|
|
|
- return LSUP_OK;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-size_t
|
|
|
-LSUP_spo_list_add_triples (
|
|
|
- LSUP_GraphIterator *it, LSUP_Term *s, const LSUP_PredObjList *po)
|
|
|
-{
|
|
|
- size_t ct = 0;
|
|
|
- if (!s) {
|
|
|
- log_error ("Subject is NULL!");
|
|
|
- return LSUP_VALUE_ERR;
|
|
|
- }
|
|
|
- if (!po->p) {
|
|
|
- log_error ("Predicate is NULL!");
|
|
|
- return LSUP_VALUE_ERR;
|
|
|
- }
|
|
|
- if (!po->o) {
|
|
|
- log_error ("Object list is NULL!");
|
|
|
- return LSUP_VALUE_ERR;
|
|
|
- }
|
|
|
- LSUP_Triple *spo = LSUP_triple_new (s, NULL, NULL);
|
|
|
- for (size_t i = 0; po->p[i]; i++) {
|
|
|
- spo->p = po->p[i];
|
|
|
- for (size_t j = 0; po->o[i][j]; j++) {
|
|
|
- spo->o = po->o[i][j];
|
|
|
-
|
|
|
- LSUP_rc rc = LSUP_graph_add_iter (it, spo);
|
|
|
- if (rc >= 0) ct++;
|
|
|
- PRCCK (rc);
|
|
|
- }
|
|
|
- }
|
|
|
- free (spo);
|
|
|
-
|
|
|
- return ct;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-LSUP_Term *
|
|
|
-LSUP_bnode_add_collection (LSUP_GraphIterator *it, LSUP_Term **ol)
|
|
|
-{
|
|
|
- LSUP_NSMap *nsm = LSUP_graph_namespace (LSUP_graph_iter_graph (it));
|
|
|
- LSUP_Term
|
|
|
- *s = LSUP_term_new (LSUP_TERM_BNODE, NULL, NULL),
|
|
|
- *rdf_first = LSUP_iriref_new ("rdf:first", nsm),
|
|
|
- *rdf_rest = LSUP_iriref_new ("rdf:rest", nsm),
|
|
|
- *rdf_nil = LSUP_iriref_new ("rdf:nil", nsm),
|
|
|
- *link;
|
|
|
-
|
|
|
- LSUP_Triple *spo = TRP_DUMMY;
|
|
|
- link = s;
|
|
|
- for (size_t i = 0; ol[i]; i++) {
|
|
|
- spo->s = link;
|
|
|
- spo->p = rdf_first;
|
|
|
- spo->o = ol[i];
|
|
|
- PRCNL (LSUP_graph_add_iter (it, spo));
|
|
|
-
|
|
|
- spo->p = rdf_rest;
|
|
|
- spo->o = (
|
|
|
- ol[i + 1] ? LSUP_term_new (LSUP_TERM_BNODE, NULL, NULL)
|
|
|
- : rdf_nil);
|
|
|
-
|
|
|
- PRCNL (LSUP_graph_add_iter (it, spo));
|
|
|
-
|
|
|
- if (link != s) LSUP_term_free (link);
|
|
|
- // Current object becomes next subject. Irrelevant for last item.
|
|
|
- link = spo->o;
|
|
|
- }
|
|
|
-
|
|
|
- LSUP_term_free (rdf_first);
|
|
|
- LSUP_term_free (rdf_rest);
|
|
|
- LSUP_term_free (rdf_nil);
|
|
|
- free (spo);
|
|
|
-
|
|
|
- return s;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
/*
|
|
|
* Extern inline functions.
|
|
|
*/
|