Skip to content

Commit

Permalink
Apply recent librdfa changes from raptor.
Browse files Browse the repository at this point in the history
Raptor commit 1f5229f5ca928600e0d35fa95be6d7118ca95b9d

    (rdfa_complete_list_triples): Init tmp for error path

 librdfa/lists.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Raptor commit 0aba31c7e901eac0832f8345b0f4deeefb223af1

    (rdfa_resolve_uri): Check end_index2 is not NULL

 librdfa/curie.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Raptor commit 0ae694d3b355f4e613b9dee397a4ddfdf4628ade

    (rdfa_complete_list_triples):  strdup and strstr output.

    (rdfa_complete_list_triples): Be careful for strdup and strstr
    returning NULL.

 librdfa/lists.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

Raptor commit 8f5b88310cae3b4c44731c3bf5dd9bc22c51ab72

    (end_element): Do not call rdfa_complete_list_triples() with no new subject

 librdfa/rdfa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Raptor commit 8939d80a6f0af8796131a1de060972474bd12773

    (rdfa_complete_object_literal_triples) strchr on NULL

    (rdfa_complete_object_literal_triples): Need non NULL
    context->xml_literal to do strchr() on it

 librdfa/triple.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Raptor commit dc5960c35485a8c084b0b067c0bc891ffa5369b5

    (rdfa_complete_current_property_value_triples): Remove duplicate variable

 librdfa/triple.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Raptor commit 9447e886ad66a1c3dd2c877341feca639824488a

    (rdfa_init_base): Fix uri_start dead code again

 librdfa/rdfa.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Raptor commit b24f25aac56afafa8053cf03fcb2239353a8e219

    (rdfa_complete_object_literal_triples): NULL check for context->xml_literal

 librdfa/triple.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Raptor commit bf1db0edfc36384ae2e12626ba54a328387dcdf4

    (end_element): Add parent_context check around block

 librdfa/rdfa.c | 94 ++++++++++++++++++++++++++++++----------------------------
 1 file changed, 48 insertions(+), 46 deletions(-)

Raptor commit 8a6cca381acc8cd6b84d96b08f70cb69740d109f

    (rdfa_init_base): Check for uri_start before use

 librdfa/rdfa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Raptor commit c9eed2429a29bf70cb86befb78a42f5cc2b8ff7e

    (rdfa_complete_list_triples): Free bnode after loop

    Also strdup() the rdf:nil string so it can be freed.

 librdfa/lists.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Raptor commit d8914ade521220525ffd3d2381828587cc980db8

    librdfa fixes for -Wunreachable-code (clang)

 librdfa/lists.c | 36 ++++++++++++++++--------------------
 librdfa/rdfa.c  | 44 ++++++++++++++++++++------------------------
 2 files changed, 36 insertions(+), 44 deletions(-)
  • Loading branch information
dajobe committed Apr 26, 2014
1 parent c165937 commit 57ca930
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 114 deletions.
8 changes: 5 additions & 3 deletions c/curie.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ char* rdfa_resolve_uri(rdfacontext* context, const char* uri)
char* end_index2;

tmpstr = rdfa_replace_string(tmpstr, context->base);
end_index2= strrchr(tmpstr, '/');
end_index2++;
*end_index2 = '\0';
end_index2 = strrchr(tmpstr, '/');
if(end_index2 != NULL) {
end_index2++;
*end_index2 = '\0';
}

rval = rdfa_join_string(tmpstr, uri);
free(tmpstr);
Expand Down
67 changes: 35 additions & 32 deletions c/lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ void rdfa_establish_new_inlist_triples(rdfacontext* context,
free(resolved_predicate);
}

if(DEBUG)
{
printf("LOCAL LIST MAPPINGS: ");
rdfa_print_mapping(context->local_list_mappings,
#if defined(DEBUG) && DEBUG > 0
printf("LOCAL LIST MAPPINGS: ");
rdfa_print_mapping(context->local_list_mappings,
(print_mapping_value_fp)rdfa_print_triple_list);
}
#endif
}

void rdfa_save_incomplete_list_triples(
Expand All @@ -85,11 +84,10 @@ void rdfa_save_incomplete_list_triples(
free(resolved_curie);
}

if(DEBUG)
{
printf("LOCAL INCOMPLETE TRIPLES: ");
rdfa_print_list(context->local_incomplete_triples);
}
#if defined(DEBUG) && DEBUG > 0
printf("LOCAL INCOMPLETE TRIPLES: ");
rdfa_print_list(context->local_incomplete_triples);
#endif
}

void rdfa_complete_list_triples(rdfacontext* context)
Expand All @@ -106,12 +104,11 @@ void rdfa_complete_list_triples(rdfacontext* context)
void* value = NULL;
unsigned int list_depth = 0;

if(DEBUG)
{
printf("local_list_mappings: ");
rdfa_print_mapping(context->local_list_mappings,
#if defined(DEBUG) && DEBUG > 0
printf("local_list_mappings: ");
rdfa_print_mapping(context->local_list_mappings,
(print_mapping_value_fp)rdfa_print_triple_list);
}
#endif

while(*mptr != NULL)
{
Expand All @@ -120,11 +117,10 @@ void rdfa_complete_list_triples(rdfacontext* context)
list = (rdfalist*)value;
list_depth = list->user_data;
mptr++;
if(DEBUG)
{
printf("LIST TRIPLES for key (%u/%u): KEY(%s)\n",
context->depth, list_depth, key);
}
#if defined(DEBUG) && DEBUG > 0
printf("LIST TRIPLES for key (%u/%u): KEY(%s)\n",
context->depth, list_depth, key);
#endif

if((context->depth < (int)list_depth) &&
(rdfa_get_list_mapping(
Expand All @@ -149,7 +145,7 @@ void rdfa_complete_list_triples(rdfacontext* context)
{
char* bnode = NULL;
char* subject;
char* tmp;
char* tmp = NULL;
bnode = rdfa_replace_string(bnode, triple->subject);
for(i = 1; i < (int)list->num_items; i++)
{
Expand Down Expand Up @@ -194,7 +190,7 @@ void rdfa_complete_list_triples(rdfacontext* context)
}
else
{
next = (char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
next = strdup((char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
}

triple = rdfa_create_triple(bnode,
Expand All @@ -216,16 +212,23 @@ void rdfa_complete_list_triples(rdfacontext* context)
* object
* first item of the 'bnode' array */
subject = strdup(key);
tmp = strstr(subject, " ");
tmp[0] = '\0';
triple = (rdftriple*)list->items[0]->data;
triple->subject =
rdfa_replace_string(triple->subject, subject);
triple->predicate =
rdfa_replace_string(triple->predicate, predicate);
context->default_graph_triple_callback(
triple, context->callback_data);
free(subject);
if(subject)
tmp = strstr(subject, " ");

if(tmp) {
tmp[0] = '\0';
triple = (rdftriple*)list->items[0]->data;
triple->subject =
rdfa_replace_string(triple->subject, subject);
triple->predicate =
rdfa_replace_string(triple->predicate, predicate);
context->default_graph_triple_callback(
triple, context->callback_data);
}
if(subject)
free(subject);
if(bnode)
free(bnode);
}

/* Free the first list item and empty the list */
Expand Down
153 changes: 77 additions & 76 deletions c/rdfa.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,20 @@ static size_t rdfa_init_base(
if(head_end != NULL)
{
char* base_start = strstr(*working_buffer, "<base ");
if(base_start == NULL)
char* href_start = NULL;
if(base_start == NULL) {
base_start = strstr(*working_buffer, "<BASE ");

if(base_start != NULL)
if(base_start != NULL)
href_start = strstr(base_start, "href=");
}

if(href_start != NULL)
{
char* href_start = strstr(base_start, "href=");
char sep = href_start[5];
char* uri_start = href_start + 6;
char* uri_end = strchr(uri_start, sep);

if((uri_start != NULL) && (uri_end != NULL))
if(uri_end != NULL)
{
if(*uri_start != sep)
{
Expand Down Expand Up @@ -241,8 +244,8 @@ static void start_element(void *parser_context, const char* name,

rdfa_push_item(context_stack, context, RDFALIST_FLAG_CONTEXT);

if(DEBUG)
{
#if defined(DEBUG) && DEBUG > 0
if(1) {
int i;

/* dump all arguments sent to this callback */
Expand Down Expand Up @@ -283,6 +286,7 @@ static void start_element(void *parser_context, const char* name,
}
fprintf(stdout, ")\n");
}
#endif

/* start the XML Literal text */
if(context->xml_literal == NULL)
Expand Down Expand Up @@ -760,8 +764,7 @@ static void start_element(void *parser_context, const char* name,
rdfa_update_language(context, xml_lang);

/***************** FOR DEBUGGING PURPOSES ONLY ******************/
if(DEBUG)
{
#if defined(DEBUG) && DEBUG > 0
printf("DEBUG: depth = %u\n", context->depth);
if(about != NULL)
{
Expand Down Expand Up @@ -815,7 +818,7 @@ static void start_element(void *parser_context, const char* name,
{
printf("DEBUG: @xml:lang = %s\n", xml_lang);
}
}
#endif

/* TODO: This isn't part of the processing model, it needs to be
* included and is a correction for the last item in step #4. */
Expand Down Expand Up @@ -866,10 +869,9 @@ static void start_element(void *parser_context, const char* name,

if(context->new_subject != NULL)
{
if(DEBUG)
{
printf("DEBUG: new_subject = %s\n", context->new_subject);
}
#if defined(DEBUG) && DEBUG > 0
printf("DEBUG: new_subject = %s\n", context->new_subject);
#endif

/* RDFa 1.0: 6. If in any of the previous steps a [new subject] was set
* to a non-null value, it is now used to provide a subject for
Expand Down Expand Up @@ -1023,13 +1025,12 @@ static void end_element(void* parser_context, const char* name,
/* append the text to the current context's XML literal */
char* buffer = (char*)malloc(strlen(name) + 4);

if(DEBUG)
{
printf("DEBUG: </%s>\n", name);
printf("context->local_list_mappings (start of end_element): ");
rdfa_print_mapping(context->local_list_mappings,
#if defined(DEBUG) && DEBUG > 0
printf("DEBUG: </%s>\n", name);
printf("context->local_list_mappings (start of end_element): ");
rdfa_print_mapping(context->local_list_mappings,
(print_mapping_value_fp)rdfa_print_triple_list);
}
#endif

sprintf(buffer, "</%s>", name);
if(context->xml_literal == NULL)
Expand Down Expand Up @@ -1108,54 +1109,56 @@ static void end_element(void* parser_context, const char* name,

/*printf(context->plain_literal);*/

/* append the XML literal and plain text literals to the parent
* literals */
if(context->xml_literal != NULL)
{
if(parent_context->xml_literal == NULL)
{
parent_context->xml_literal =
rdfa_replace_string(
parent_context->xml_literal, context->xml_literal);
parent_context->xml_literal_size = context->xml_literal_size;
}
else
{
parent_context->xml_literal =
rdfa_n_append_string(
parent_context->xml_literal,
&parent_context->xml_literal_size,
context->xml_literal, context->xml_literal_size);
}
if(parent_context != NULL) {
/* append the XML literal and plain text literals to the parent
* literals */
if(context->xml_literal != NULL)
{
if(parent_context->xml_literal == NULL)
{
parent_context->xml_literal =
rdfa_replace_string(
parent_context->xml_literal, context->xml_literal);
parent_context->xml_literal_size = context->xml_literal_size;
}
else
{
parent_context->xml_literal =
rdfa_n_append_string(
parent_context->xml_literal,
&parent_context->xml_literal_size,
context->xml_literal, context->xml_literal_size);
}

/* if there is an XML literal, there is probably a plain literal */
if(context->plain_literal != NULL)
{
if(parent_context->plain_literal == NULL)
{
parent_context->plain_literal =
rdfa_replace_string(
parent_context->plain_literal, context->plain_literal);
parent_context->plain_literal_size =
context->plain_literal_size;
}
else
{
parent_context->plain_literal =
rdfa_n_append_string(
parent_context->plain_literal,
&parent_context->plain_literal_size,
context->plain_literal,
context->plain_literal_size);
}
}
}
/* if there is an XML literal, there is probably a plain literal */
if(context->plain_literal != NULL)
{
if(parent_context->plain_literal == NULL)
{
parent_context->plain_literal =
rdfa_replace_string(
parent_context->plain_literal, context->plain_literal);
parent_context->plain_literal_size =
context->plain_literal_size;
}
else
{
parent_context->plain_literal =
rdfa_n_append_string(
parent_context->plain_literal,
&parent_context->plain_literal_size,
context->plain_literal,
context->plain_literal_size);
}
}
}

/* preserve the bnode count by copying it to the parent_context */
parent_context->bnode_count = context->bnode_count;
parent_context->underscore_colon_bnode_name = \
rdfa_replace_string(parent_context->underscore_colon_bnode_name,
context->underscore_colon_bnode_name);
/* preserve the bnode count by copying it to the parent_context */
parent_context->bnode_count = context->bnode_count;
parent_context->underscore_colon_bnode_name = \
rdfa_replace_string(parent_context->underscore_colon_bnode_name,
context->underscore_colon_bnode_name);
}

/* 10. If the [ skip element ] flag is 'false', and [ new subject ]
* was set to a non-null value, then any [ incomplete triple ]s
Expand All @@ -1167,7 +1170,7 @@ static void end_element(void* parser_context, const char* name,

/* 14. Once all the child elements have been traversed, list triples are
* generated, if necessary. */
if(context->rdfa_version == RDFA_VERSION_1_1)
if(context->rdfa_version == RDFA_VERSION_1_1 && (context->new_subject != NULL))
{
rdfa_complete_list_triples(context);

Expand All @@ -1180,12 +1183,11 @@ static void end_element(void* parser_context, const char* name,
(void**)context->local_list_mappings,
(copy_mapping_value_fp)rdfa_replace_list);

if(DEBUG)
{
printf("parent_context->local_list_mappings (after copy): ");
rdfa_print_mapping(context->local_list_mappings,
#if defined(DEBUG) && DEBUG > 0
printf("parent_context->local_list_mappings (after copy): ");
rdfa_print_mapping(context->local_list_mappings,
(print_mapping_value_fp)rdfa_print_triple_list);
}
#endif
rdfa_free_mapping(context->local_list_mappings,
(free_mapping_value_fp)rdfa_free_list);
context->local_list_mappings = NULL;
Expand All @@ -1195,10 +1197,9 @@ static void end_element(void* parser_context, const char* name,
/* free the context */
rdfa_free_context(context);

if(DEBUG)
{
printf("-------------------------------------------------------------\n");
}
#if defined(DEBUG) && DEBUG > 0
printf("-------------------------------------------------------------\n");
#endif
}

void rdfa_set_default_graph_triple_handler(
Expand Down
Loading

0 comments on commit 57ca930

Please sign in to comment.