static void rasqal_rowsource_write_indent(raptor_iostream *iostr, unsigned int indent) { while(indent > 0) { unsigned int sp = (indent > SPACES_LENGTH) ? SPACES_LENGTH : indent; raptor_iostream_write_bytes(spaces, sizeof(char), RASQAL_GOOD_CAST(size_t, sp), iostr); indent -= sp; } }
static int rasqal_join_rowsource_ensure_variables(rasqal_rowsource* rowsource, void *user_data) { rasqal_join_rowsource_context* con; int map_size; int i; con = (rasqal_join_rowsource_context*)user_data; if(rasqal_rowsource_ensure_variables(con->left)) return 1; if(rasqal_rowsource_ensure_variables(con->right)) return 1; map_size = rasqal_rowsource_get_size(con->right); con->right_map = RASQAL_MALLOC(int*, RASQAL_GOOD_CAST(size_t, sizeof(int) * RASQAL_GOOD_CAST(size_t, map_size))); if(!con->right_map) return 1; rowsource->size = 0; /* copy in variables from left rowsource */ if(rasqal_rowsource_copy_variables(rowsource, con->left)) return 1; /* add any new variables not already seen from right rowsource */ for(i = 0; i < map_size; i++) { rasqal_variable* v; int offset; v = rasqal_rowsource_get_variable_by_offset(con->right, i); if(!v) break; offset = rasqal_rowsource_add_variable(rowsource, v); if(offset < 0) return 1; con->right_map[i] = offset; } return 0; }
static rasqal_query* roqet_init_query(rasqal_world *world, const char* ql_name, const char* ql_uri, const unsigned char* query_string, raptor_uri* base_uri, rasqal_feature query_feature, int query_feature_value, const unsigned char* query_feature_string_value, int store_results, raptor_sequence* data_graphs) { rasqal_query* rq; rq = rasqal_new_query(world, (const char*)ql_name, (const unsigned char*)ql_uri); if(!rq) { fprintf(stderr, "%s: Failed to create query name %s\n", program, ql_name); goto tidy_query; } if(query_feature_value >= 0) rasqal_query_set_feature(rq, query_feature, query_feature_value); if(query_feature_string_value) rasqal_query_set_feature_string(rq, query_feature, query_feature_string_value); #ifdef STORE_RESULTS_FLAG if(store_results >= 0) rasqal_query_set_store_results(rq, store_results); #endif if(rasqal_query_prepare(rq, query_string, base_uri)) { size_t len = strlen((const char*)query_string); fprintf(stderr, "%s: Parsing query '", program); if(len > MAX_QUERY_ERROR_REPORT_LEN) { (void)fwrite(query_string, RASQAL_GOOD_CAST(size_t, MAX_QUERY_ERROR_REPORT_LEN), sizeof(char), stderr); fprintf(stderr, "...' (%d bytes) failed\n", RASQAL_BAD_CAST(int, len)); } else {
static rasqal_row* rasqal_new_row_common(rasqal_world* world, int size, int order_size) { rasqal_row* row; row = RASQAL_CALLOC(rasqal_row*, 1, sizeof(*row)); if(!row) return NULL; row->usage = 1; row->size = size; row->order_size = order_size; if(row->size > 0) { row->values = RASQAL_CALLOC(rasqal_literal**, RASQAL_GOOD_CAST(size_t, row->size), sizeof(rasqal_literal*)); if(!row->values) { rasqal_free_row(row); return NULL; } }
/* * rasqal_ntriples_parse_term_internal: * @world: rasqal world * @locator: locator object (in/out) (or NULL) * @start: pointer to starting character of string (in) * @dest: destination of string (in) * @lenp: pointer to length of string (in/out) * @dest_lenp: pointer to length of destination string (out) * @end_char: string ending character * @class: string class * * INTERNAL - Parse an N-Triples term with escapes. * * Relies that @dest is long enough; it need only be as large as the * input string @start since when UTF-8 encoding, the escapes are * removed and the result is always less than or equal to length of * input. * * N-Triples strings / URIs are written in ASCII at present; * characters outside the printable ASCII range are discarded with a * warning. See the grammar for full details of the allowed ranges. * * UTF-8 and the \u and \U esapes are both allowed. * * Return value: Non 0 on failure **/ static int rasqal_ntriples_parse_term_internal(rasqal_world* world, raptor_locator* locator, const unsigned char **start, unsigned char *dest, size_t *lenp, size_t *dest_lenp, char end_char, rasqal_ntriples_term_class term_class) { const unsigned char *p = *start; unsigned char c = '\0'; size_t ulen = 0; unsigned long unichar = 0; unsigned int position = 0; int end_char_seen = 0; /* find end of string, fixing backslashed characters on the way */ while(*lenp > 0) { int unichar_width; c = *p; p++; (*lenp)--; if(locator) { locator->column++; locator->byte++; } if(c > 0x7f) { /* just copy the UTF-8 bytes through */ int unichar_len; unichar_len = raptor_unicode_utf8_string_get_char(p - 1, 1 + *lenp, NULL); if(unichar_len < 0 || RASQAL_GOOD_CAST(size_t, unichar_len) > *lenp) { rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, locator, "UTF-8 encoding error at character %d (0x%02X) found.", c, c); /* UTF-8 encoding had an error or ended in the middle of a string */ return 1; } memmove(dest, p-1, unichar_len); dest += unichar_len; unichar_len--; /* p, *lenp were moved on by 1 earlier */ p += unichar_len; (*lenp) -= unichar_len; if(locator) { locator->column += unichar_len; locator->byte += unichar_len; } continue; } if(c != '\\') { /* finish at non-backslashed end_char */ if(end_char && c == end_char) { end_char_seen = 1; break; } if(!rasqal_ntriples_term_valid(c, position, term_class)) { if(end_char) { /* end char was expected, so finding an invalid thing is an error */ rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, locator, "Missing terminating '%c' (found '%c')", end_char, c); return 0; } else { /* it's the end - so rewind 1 to save next char */ p--; (*lenp)++; if(locator) { locator->column--; locator->byte--; } if(term_class == RASQAL_TERM_CLASS_BNODEID && dest[-1] == '.') { /* If bnode id ended on '.' move back one */ dest--; p--; (*lenp)++; if(locator) { locator->column--; locator->byte--; } } break; } } /* otherwise store and move on */ *dest++ = c; position++; continue; } if(!*lenp) { rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, locator, "\\ at end of input."); return 0; } c = *p; p++; (*lenp)--; if(locator) { locator->column++; locator->byte++; } switch(c) { case '"': case '\\': *dest++ = c; break; case 'b': *dest++ = '\b'; break; case 'f': *dest++ = '\f'; break; case 'n': *dest++ = '\n'; break; case 'r': *dest++ = '\r'; break; case 't': *dest++ = '\t'; break; case '<': case '>': case '{': case '}': case '|': case '^': case '`': /* Turtle 2013 allows these in URIs (as well as \" and \\) */ *dest++ = c; break; case 'u': case 'U': ulen = (c == 'u') ? 4 : 8; if(*lenp < ulen) { rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, locator, "%c over end of input.", c); return 0; } if(1) { unsigned int ii; int n = 0; for(ii = 0; ii < ulen; ii++) { char cc = p[ii]; if(!isxdigit(RASQAL_GOOD_CAST(char, cc))) { rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, locator, "N-Triples string error - illegal hex digit %c in Unicode escape '%c%s...'", cc, c, p); n = 1; break; } } if(n) break; n = sscanf((const char*)p, ((ulen == 4) ? "%04lx" : "%08lx"), &unichar); if(n != 1) { rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, locator, "Illegal Uncode escape '%c%s...'", c, p); break; } } p += ulen; (*lenp) -= ulen; if(locator) { locator->column += RASQAL_GOOD_CAST(int, ulen); locator->byte += RASQAL_GOOD_CAST(int, ulen); } if(unichar > rasqal_unicode_max_codepoint) { rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, locator, "Illegal Unicode character with code point #x%lX (max #x%lX).", unichar, rasqal_unicode_max_codepoint); break; } unichar_width = raptor_unicode_utf8_string_put_char(unichar, dest, 4); if(unichar_width < 0) { rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, locator, "Illegal Unicode character with code point #x%lX.", unichar); break; } /* The destination length is set here to 4 since we know that in * all cases, the UTF-8 encoded output sequence is always shorter * than the input sequence, and the buffer is edited in place. * \uXXXX: 6 bytes input - UTF-8 max 3 bytes output * \uXXXXXXXX: 10 bytes input - UTF-8 max 4 bytes output */ dest += (int)unichar_width; break; default: rasqal_log_error_simple(world, RAPTOR_LOG_LEVEL_ERROR, locator, "Illegal string escape \\%c in \"%s\"", c, (char*)start); return 0; } position++; } /* end while */