aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--serd/serd.h16
-rw-r--r--src/env.c32
-rw-r--r--src/node.c8
-rw-r--r--src/reader.c83
-rw-r--r--src/serd_internal.h2
-rw-r--r--src/string.c4
-rw-r--r--src/uri.c28
-rw-r--r--src/writer.c2
-rw-r--r--wscript1
9 files changed, 88 insertions, 88 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 1c31fb14..dbabd4d9 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -370,11 +370,13 @@ SerdStatus
serd_uri_parse(const uint8_t* utf8, SerdURI* out);
/**
- Set `out` to `uri` resolved against `base`.
+ Set target `t` to reference `r` resolved against `base`.
+
+ @see http://tools.ietf.org/html/rfc3986#section-5.2.2
*/
SERD_API
void
-serd_uri_resolve(const SerdURI* uri, const SerdURI* base, SerdURI* out);
+serd_uri_resolve(const SerdURI* r, const SerdURI* base, SerdURI* t);
/**
Function to detect I/O stream errors.
@@ -766,7 +768,7 @@ SERD_API
void
serd_reader_set_error_sink(SerdReader* reader,
SerdErrorSink error_sink,
- void* handle);
+ void* error_handle);
/**
Return the `handle` passed to serd_reader_new().
@@ -908,7 +910,7 @@ serd_writer_new(SerdSyntax syntax,
SerdStyle style,
SerdEnv* env,
const SerdURI* base_uri,
- SerdSink sink,
+ SerdSink ssink,
void* stream);
/**
@@ -967,7 +969,7 @@ SERD_API
void
serd_writer_set_error_sink(SerdWriter* writer,
SerdErrorSink error_sink,
- void* handle);
+ void* error_handle);
/**
Set a prefix to be removed from matching blank node identifiers.
@@ -1026,8 +1028,8 @@ serd_writer_write_statement(SerdWriter* writer,
const SerdNode* subject,
const SerdNode* predicate,
const SerdNode* object,
- const SerdNode* object_datatype,
- const SerdNode* object_lang);
+ const SerdNode* datatype,
+ const SerdNode* lang);
/**
Mark the end of an anonymous node's description.
diff --git a/src/env.c b/src/env.c
index 92cb4150..adda27ba 100644
--- a/src/env.c
+++ b/src/env.c
@@ -69,16 +69,16 @@ serd_env_get_base_uri(const SerdEnv* env,
SERD_API
SerdStatus
serd_env_set_base_uri(SerdEnv* env,
- const SerdNode* uri_node)
+ const SerdNode* uri)
{
- if (!env || !uri_node) {
+ if (!env || !uri) {
return SERD_ERR_BAD_ARG;
}
// Resolve base URI and create a new node and URI for it
SerdURI base_uri;
SerdNode base_uri_node = serd_node_new_uri_from_node(
- uri_node, &env->base_uri, &base_uri);
+ uri, &env->base_uri, &base_uri);
if (base_uri_node.buf) {
// Replace the current base URI
@@ -128,18 +128,18 @@ SERD_API
SerdStatus
serd_env_set_prefix(SerdEnv* env,
const SerdNode* name,
- const SerdNode* uri_node)
+ const SerdNode* uri)
{
- if (!name->buf || uri_node->type != SERD_URI) {
+ if (!name->buf || uri->type != SERD_URI) {
return SERD_ERR_BAD_ARG;
- } else if (serd_uri_string_has_scheme(uri_node->buf)) {
+ } else if (serd_uri_string_has_scheme(uri->buf)) {
// Set prefix to absolute URI
- serd_env_add(env, name, uri_node);
+ serd_env_add(env, name, uri);
} else {
// Resolve relative URI and create a new node and URI for it
SerdURI abs_uri;
SerdNode abs_uri_node = serd_node_new_uri_from_node(
- uri_node, &env->base_uri, &abs_uri);
+ uri, &env->base_uri, &abs_uri);
// Set prefix to resolved (absolute) URI
serd_env_add(env, name, &abs_uri_node);
@@ -185,7 +185,7 @@ SERD_API
bool
serd_env_qualify(const SerdEnv* env,
const SerdNode* uri,
- SerdNode* prefix_name,
+ SerdNode* prefix,
SerdChunk* suffix)
{
for (size_t i = 0; i < env->n_prefixes; ++i) {
@@ -194,7 +194,7 @@ serd_env_qualify(const SerdEnv* env,
if (!strncmp((const char*)uri->buf,
(const char*)prefix_uri->buf,
prefix_uri->n_bytes)) {
- *prefix_name = env->prefixes[i].name;
+ *prefix = env->prefixes[i].name;
suffix->buf = uri->buf + prefix_uri->n_bytes;
suffix->len = uri->n_bytes - prefix_uri->n_bytes;
if (is_name(suffix->buf, suffix->len)) {
@@ -209,23 +209,23 @@ serd_env_qualify(const SerdEnv* env,
SERD_API
SerdStatus
serd_env_expand(const SerdEnv* env,
- const SerdNode* qname,
+ const SerdNode* curie,
SerdChunk* uri_prefix,
SerdChunk* uri_suffix)
{
const uint8_t* const colon = (const uint8_t*)memchr(
- qname->buf, ':', qname->n_bytes + 1);
+ curie->buf, ':', curie->n_bytes + 1);
if (!colon) {
- return SERD_ERR_BAD_ARG; // Invalid qname
+ return SERD_ERR_BAD_ARG; // Invalid CURIE
}
- const size_t name_len = colon - qname->buf;
- const SerdPrefix* const prefix = serd_env_find(env, qname->buf, name_len);
+ const size_t name_len = colon - curie->buf;
+ const SerdPrefix* const prefix = serd_env_find(env, curie->buf, name_len);
if (prefix) {
uri_prefix->buf = prefix->uri.buf;
uri_prefix->len = prefix->uri.n_bytes;
uri_suffix->buf = colon + 1;
- uri_suffix->len = qname->n_bytes - (colon - qname->buf) - 1;
+ uri_suffix->len = curie->n_bytes - (colon - curie->buf) - 1;
return SERD_SUCCESS;
}
return SERD_ERR_NOT_FOUND;
diff --git a/src/node.c b/src/node.c
index c25e06a0..42992917 100644
--- a/src/node.c
+++ b/src/node.c
@@ -33,16 +33,16 @@
SERD_API
SerdNode
-serd_node_from_string(SerdType type, const uint8_t* buf)
+serd_node_from_string(SerdType type, const uint8_t* str)
{
- if (!buf) {
+ if (!str) {
return SERD_NODE_NULL;
}
uint32_t flags = 0;
size_t buf_n_bytes = 0;
- const size_t buf_n_chars = serd_strlen(buf, &buf_n_bytes, &flags);
- SerdNode ret = { buf, buf_n_bytes, buf_n_chars, flags, type };
+ const size_t buf_n_chars = serd_strlen(str, &buf_n_bytes, &flags);
+ SerdNode ret = { str, buf_n_bytes, buf_n_chars, flags, type };
return ret;
}
diff --git a/src/reader.c b/src/reader.c
index 54e2724a..0ea95fcc 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -189,7 +189,7 @@ push_node_padded(SerdReader* reader, size_t maxlen,
#ifdef SERD_STACK_CHECK
reader->allocs = realloc(
- reader->allocs, sizeof(uint8_t*) * (++reader->n_allocs));
+ reader->allocs, sizeof(reader->allocs) * (++reader->n_allocs));
reader->allocs[reader->n_allocs - 1] = ((uint8_t*)mem - reader->stack.buf);
#endif
return (uint8_t*)node - reader->stack.buf;
@@ -278,10 +278,9 @@ read_HEX(SerdReader* reader)
const uint8_t c = peek_byte(reader);
if (is_digit(c) || in_range(c, 'A', 'F') || in_range(c, 'a', 'f')) {
return eat_byte_safe(reader, c);
- } else {
- return r_err(reader, SERD_ERR_BAD_SYNTAX,
- "invalid hexadecimal digit `%c'\n", c);
}
+ return r_err(reader, SERD_ERR_BAD_SYNTAX,
+ "invalid hexadecimal digit `%c'\n", c);
}
// Read UCHAR escape, initial \ is already eaten by caller
@@ -456,9 +455,8 @@ read_character(SerdReader* reader, Ref dest, SerdNodeFlags* flags, uint8_t c)
}
push_byte(reader, dest, c);
return SERD_SUCCESS;
- } else {
- return read_utf8_character(reader, dest, c);
}
+ return read_utf8_character(reader, dest, c);
}
// [10] comment ::= '#' ( [^#xA #xD] )*
@@ -540,11 +538,10 @@ read_STRING_LITERAL_LONG(SerdReader* reader, SerdNodeFlags* flags, uint8_t q)
if (q2 == q && q3 == q) { // End of string
eat_byte_safe(reader, q3);
return ref;
- } else {
- *flags |= SERD_HAS_QUOTE;
- push_byte(reader, ref, c);
- read_character(reader, ref, flags, q2);
}
+ *flags |= SERD_HAS_QUOTE;
+ push_byte(reader, ref, c);
+ read_character(reader, ref, flags, q2);
} else {
read_character(reader, ref, flags, eat_byte_safe(reader, c));
}
@@ -672,11 +669,10 @@ read_PLX(SerdReader* reader, Ref dest)
if (is_alpha(c = peek_byte(reader))) {
// Escapes like \u \n etc. are not supported
return SERD_ERR_BAD_SYNTAX;
- } else {
- // Allow escaping of pretty much any other character
- push_byte(reader, dest, eat_byte_safe(reader, c));
- return SERD_SUCCESS;
}
+ // Allow escaping of pretty much any other character
+ push_byte(reader, dest, eat_byte_safe(reader, c));
+ return SERD_SUCCESS;
default:
return SERD_FAILURE;
}
@@ -1001,27 +997,26 @@ read_verb(SerdReader* reader, Ref* dest)
{
if (peek_byte(reader) == '<') {
return (*dest = read_IRIREF(reader));
- } else {
- /* Either a qname, or "a". Read the prefix first, and if it is in fact
- "a", produce that instead.
- */
- *dest = push_node(reader, SERD_CURIE, "", 0);
- SerdNode* node = deref(reader, *dest);
- const SerdStatus st = read_PN_PREFIX(reader, *dest);
- bool ate_dot = false;
- if (!st && node->n_bytes == 1 && node->buf[0] == 'a' &&
- is_token_end(peek_byte(reader))) {
- pop_node(reader, *dest);
- return (*dest = push_node(reader, SERD_URI, NS_RDF "type", 47));
- } else if (st > SERD_FAILURE ||
- !read_PrefixedName(reader, *dest, false, &ate_dot) ||
- ate_dot) {
- return (*dest = pop_node(reader, *dest));
- } else {
- return true;
- }
}
- return false;
+
+ /* Either a qname, or "a". Read the prefix first, and if it is in fact
+ "a", produce that instead.
+ */
+ *dest = push_node(reader, SERD_CURIE, "", 0);
+ SerdNode* node = deref(reader, *dest);
+ const SerdStatus st = read_PN_PREFIX(reader, *dest);
+ bool ate_dot = false;
+ if (!st && node->n_bytes == 1 && node->buf[0] == 'a' &&
+ is_token_end(peek_byte(reader))) {
+ pop_node(reader, *dest);
+ return (*dest = push_node(reader, SERD_URI, NS_RDF "type", 47));
+ } else if (st > SERD_FAILURE ||
+ !read_PrefixedName(reader, *dest, false, &ate_dot) ||
+ ate_dot) {
+ return (*dest = pop_node(reader, *dest));
+ }
+
+ return true;
}
static Ref
@@ -1901,16 +1896,18 @@ serd_reader_end_stream(SerdReader* me)
SERD_API
SerdStatus
-serd_reader_read_file_handle(SerdReader* me, FILE* file, const uint8_t* name)
+serd_reader_read_file_handle(SerdReader* reader,
+ FILE* file,
+ const uint8_t* name)
{
return serd_reader_read_source(
- me, (SerdSource)fread, (SerdStreamErrorFunc)ferror,
+ reader, (SerdSource)fread, (SerdStreamErrorFunc)ferror,
file, name, SERD_PAGE_SIZE);
}
SERD_API
SerdStatus
-serd_reader_read_source(SerdReader* me,
+serd_reader_read_source(SerdReader* reader,
SerdSource source,
SerdStreamErrorFunc error,
void* stream,
@@ -1918,17 +1915,17 @@ serd_reader_read_source(SerdReader* me,
size_t page_size)
{
SerdStatus st = serd_reader_start_source_stream(
- me, source, error, stream, name, page_size);
+ reader, source, error, stream, name, page_size);
- if ((st = serd_reader_prepare(me))) {
- serd_reader_end_stream(me);
+ if (st || (st = serd_reader_prepare(reader))) {
+ serd_reader_end_stream(reader);
return st;
- } else if (!read_doc(me)) {
- serd_reader_end_stream(me);
+ } else if (!read_doc(reader)) {
+ serd_reader_end_stream(reader);
return SERD_ERR_UNKNOWN;
}
- return serd_reader_end_stream(me);
+ return serd_reader_end_stream(reader);
}
SERD_API
diff --git a/src/serd_internal.h b/src/serd_internal.h
index 297b4507..aa5b3c53 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -43,7 +43,7 @@
static inline FILE*
serd_fopen(const char* path, const char* mode)
{
- FILE* fd = fopen((const char*)path, mode);
+ FILE* fd = fopen(path, mode);
if (!fd) {
fprintf(stderr, "Error opening file %s (%s)\n", path, strerror(errno));
return NULL;
diff --git a/src/string.c b/src/string.c
index 1e653795..9381015d 100644
--- a/src/string.c
+++ b/src/string.c
@@ -20,9 +20,9 @@
SERD_API
const uint8_t*
-serd_strerror(SerdStatus st)
+serd_strerror(SerdStatus status)
{
- switch (st) {
+ switch (status) {
case SERD_SUCCESS: return (const uint8_t*)"Success";
case SERD_FAILURE: return (const uint8_t*)"Non-fatal failure";
case SERD_ERR_UNKNOWN: return (const uint8_t*)"Unknown error";
diff --git a/src/uri.c b/src/uri.c
index fcea3b62..543b2305 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -137,9 +137,9 @@ serd_uri_dump(const SerdURI* uri, FILE* file)
SERD_API
SerdStatus
-serd_uri_parse(const uint8_t* utf8, SerdURI* uri)
+serd_uri_parse(const uint8_t* utf8, SerdURI* out)
{
- *uri = SERD_URI_NULL;
+ *out = SERD_URI_NULL;
const uint8_t* ptr = utf8;
@@ -155,8 +155,8 @@ serd_uri_parse(const uint8_t* utf8, SerdURI* uri)
ptr = utf8;
goto path; // Relative URI (starts with path by definition)
case ':':
- uri->scheme.buf = utf8;
- uri->scheme.len = (ptr++) - utf8;
+ out->scheme.buf = utf8;
+ out->scheme.len = (ptr++) - utf8;
goto maybe_authority; // URI with scheme
case '+': case '-': case '.':
continue;
@@ -175,14 +175,14 @@ serd_uri_parse(const uint8_t* utf8, SerdURI* uri)
maybe_authority:
if (*ptr == '/' && *(ptr + 1) == '/') {
ptr += 2;
- uri->authority.buf = ptr;
+ out->authority.buf = ptr;
for (uint8_t c; (c = *ptr) != '\0'; ++ptr) {
switch (c) {
case '/': goto path;
case '?': goto query;
case '#': goto fragment;
default:
- ++uri->authority.len;
+ ++out->authority.len;
}
}
}
@@ -197,14 +197,14 @@ path:
case '\0': goto end;
default: break;
}
- uri->path.buf = ptr;
- uri->path.len = 0;
+ out->path.buf = ptr;
+ out->path.len = 0;
for (uint8_t c; (c = *ptr) != '\0'; ++ptr) {
switch (c) {
case '?': goto query;
case '#': goto fragment;
default:
- ++uri->path.len;
+ ++out->path.len;
}
}
@@ -214,13 +214,13 @@ path:
*/
query:
if (*ptr == '?') {
- uri->query.buf = ++ptr;
+ out->query.buf = ++ptr;
for (uint8_t c; (c = *ptr) != '\0'; ++ptr) {
switch (c) {
case '#':
goto fragment;
default:
- ++uri->query.len;
+ ++out->query.len;
}
}
}
@@ -231,16 +231,16 @@ query:
*/
fragment:
if (*ptr == '#') {
- uri->fragment.buf = ptr;
+ out->fragment.buf = ptr;
while (*ptr++ != '\0') {
- ++uri->fragment.len;
+ ++out->fragment.len;
}
}
end:
#ifdef URI_DEBUG
fprintf(stderr, "PARSE URI <%s>\n", utf8);
- serd_uri_dump(uri, stderr);
+ serd_uri_dump(out, stderr);
fprintf(stderr, "\n");
#endif
diff --git a/src/writer.c b/src/writer.c
index 3c3bbb48..75d61bc8 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -669,7 +669,7 @@ serd_writer_write_statement(SerdWriter* writer,
}
#define TRY(write_result) \
- if (!write_result) { \
+ if (!(write_result)) { \
return SERD_ERR_UNKNOWN; \
}
diff --git a/wscript b/wscript
index 3aff945c..b39e43a8 100644
--- a/wscript
+++ b/wscript
@@ -211,6 +211,7 @@ def build(bld):
def lint(ctx):
subprocess.call('cpplint.py --filter=+whitespace/comments,-whitespace/tab,-whitespace/braces,-whitespace/labels,-build/header_guard,-readability/casting,-readability/todo,-build/include src/* serd/*', shell=True)
+ subprocess.call('clang-tidy -checks="*,-misc-unused-parameters,-readability-else-after-return,-llvm-header-guard,-google-readability-todo,-clang-analyzer-alpha.*" -extra-arg="-std=c99" -extra-arg="-I." -extra-arg="-Ibuild" ./serd/*.h ./src/*.c ./src/*.h', shell=True)
def amalgamate(ctx):
shutil.copy('serd/serd.h', 'build/serd.h')